Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
xAAL
Code
Python
Commits
386afa4c
Commit
386afa4c
authored
4 months ago
by
KERDREUX Jerome
Browse files
Options
Downloads
Patches
Plain Diff
Timer and Hooks now accept func and coro functions
parent
aa0b7365
No related branches found
No related tags found
1 merge request
!1
First try of type hints
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
libs/lib/xaal/lib/aioengine.py
+3
-3
3 additions, 3 deletions
libs/lib/xaal/lib/aioengine.py
libs/lib/xaal/lib/core.py
+5
-3
5 additions, 3 deletions
libs/lib/xaal/lib/core.py
with
8 additions
and
6 deletions
libs/lib/xaal/lib/aioengine.py
+
3
−
3
View file @
386afa4c
...
...
@@ -36,7 +36,7 @@ class HookType(Enum):
class
Hook
(
object
):
__slots__
=
[
'
type
'
,
'
func
'
,
'
args
'
,
'
kwargs
'
]
def
__init__
(
self
,
type_
:
HookType
,
func
:
Any
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
type_
:
HookType
,
func
:
core
.
FuncT
,
*
args
,
**
kwargs
):
# func has to be a callable, but it can be a coroutine or a function
self
.
type
=
type_
self
.
func
=
func
...
...
@@ -83,11 +83,11 @@ class AsyncEngine(core.EngineMixin):
#####################################################
# Hooks
#####################################################
def
on_start
(
self
,
func
:
Any
,
*
args
,
**
kwargs
):
def
on_start
(
self
,
func
:
core
.
FuncT
,
*
args
,
**
kwargs
):
hook
=
Hook
(
HookType
.
start
,
func
,
*
args
,
**
kwargs
)
self
.
_hooks
.
append
(
hook
)
def
on_stop
(
self
,
func
:
Any
,
*
args
,
**
kwargs
):
def
on_stop
(
self
,
func
:
core
.
FuncT
,
*
args
,
**
kwargs
):
hook
=
Hook
(
HookType
.
stop
,
func
,
*
args
,
**
kwargs
)
self
.
_hooks
.
append
(
hook
)
...
...
This diff is collapsed.
Click to expand it.
libs/lib/xaal/lib/core.py
+
5
−
3
View file @
386afa4c
...
...
@@ -22,7 +22,7 @@ import inspect
import
logging
import
time
import
typing
from
typing
import
Any
,
Optional
,
List
,
Callable
from
typing
import
Any
,
Awaitable
,
Optional
,
List
,
Callable
,
Union
,
TypeVar
from
.exceptions
import
EngineError
,
XAALError
from
.messages
import
ALIVE_ADDR
,
MessageAction
,
MessageFactory
,
MessageType
...
...
@@ -32,6 +32,7 @@ if typing.TYPE_CHECKING:
from
.messages
import
Message
FuncT
=
TypeVar
(
"
FuncT
"
,
Callable
[[],
None
],
Callable
[[],
Awaitable
[
None
]])
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -39,7 +40,7 @@ logger = logging.getLogger(__name__)
# Timer class
#####################################################
class
Timer
(
object
):
def
__init__
(
self
,
func
:
Any
,
period
:
int
,
counter
:
int
):
def
__init__
(
self
,
func
:
FuncT
,
period
:
int
,
counter
:
int
):
# Timer function should a Callable[[],None], but it can be a coroutine too
self
.
func
=
func
self
.
period
=
period
...
...
@@ -208,7 +209,8 @@ class EngineMixin(object):
#####################################################
# timers
#####################################################
def
add_timer
(
self
,
func
:
Any
,
period
:
int
,
counter
:
int
=
-
1
):
from
typing
import
Coroutine
def
add_timer
(
self
,
func
:
FuncT
,
period
:
int
,
counter
:
int
=
-
1
):
"""
func: function to call
period: period in second
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment