@ -42,7 +42,7 @@ def on_close(workflow: loop.Task) -> None:
if not tasks and default_constructor :
if not tasks and default_constructor :
# If no workflows are running, we should create a new default workflow
# If no workflows are running, we should create a new default workflow
# and run it.
# and run it.
start_default ( default_constructor )
start_default ( )
if __debug__ :
if __debug__ :
# In debug builds, we dump a memory info right after a workflow is
# In debug builds, we dump a memory info right after a workflow is
# finished.
# finished.
@ -50,18 +50,19 @@ def on_close(workflow: loop.Task) -> None:
micropython . mem_info ( )
micropython . mem_info ( )
def start_default ( constructor : Callable [ [ ] , loop . Task ] ) - > None :
def start_default ( ) - > None :
""" Start a default workflow , created from `constructor` .
""" Start a default workflow .
If a default task is already running , nothing will happen . Use ` replace_default `
Use ` set_default ` to set the default workflow constructor .
to set up a new default task for the next ru n.
If a default task is already running , nothing will happe n.
"""
"""
global default_task
global default_task
global default_constructor
global default_constructor
assert default_constructor is not None
if not default_task :
if not default_task :
default_constructor = constructor
default_task = default_constructor ( )
default_task = constructor ( )
if __debug__ :
if __debug__ :
log . debug ( __name__ , " start default: %s " , default_task )
log . debug ( __name__ , " start default: %s " , default_task )
# Schedule the default task. Because the task can complete on its own,
# Schedule the default task. Because the task can complete on its own,
@ -72,7 +73,7 @@ def start_default(constructor: Callable[[], loop.Task]) -> None:
log . debug ( __name__ , " default already started " )
log . debug ( __name__ , " default already started " )
def replace _default( constructor : Callable [ [ ] , loop . Task ] ) - > None :
def set _default( constructor : Callable [ [ ] , loop . Task ] ) - > None :
""" Configure a default workflow, which will be started next time it is needed. """
""" Configure a default workflow, which will be started next time it is needed. """
global default_constructor
global default_constructor
if __debug__ :
if __debug__ :
@ -111,7 +112,7 @@ def _finalize_default(task: loop.Task, value: Any) -> None:
# finalizer, so when this function finished, nothing will be running.
# finalizer, so when this function finished, nothing will be running.
# We must schedule a new instance of the default now.
# We must schedule a new instance of the default now.
if default_constructor is not None :
if default_constructor is not None :
start_default ( default_constructor )
start_default ( )
else :
else :
raise RuntimeError # no tasks and no default constructor
raise RuntimeError # no tasks and no default constructor