mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 15:38:11 +00:00
workflow: less verbose naming
This commit is contained in:
parent
6d5514ac4a
commit
492e71f147
@ -1,37 +1,38 @@
|
|||||||
from trezor import log, loop
|
from trezor import log, loop
|
||||||
|
|
||||||
_started_workflows = []
|
_started = []
|
||||||
_default_workflow = None
|
_default = None
|
||||||
_default_workflow_genfunc = None
|
_default_genfunc = None
|
||||||
|
|
||||||
|
|
||||||
def start_default(genfunc):
|
def start_default(genfunc):
|
||||||
global _default_workflow
|
global _default
|
||||||
global _default_workflow_genfunc
|
global _default_genfunc
|
||||||
_default_workflow_genfunc = genfunc
|
_default_genfunc = genfunc
|
||||||
_default_workflow = _default_workflow_genfunc()
|
_default = _default_genfunc()
|
||||||
log.info(__name__, 'starting default workflow %s', _default_workflow)
|
log.info(__name__, 'start default %s', _default)
|
||||||
loop.schedule_task(_default_workflow)
|
loop.schedule_task(_default)
|
||||||
|
|
||||||
|
|
||||||
|
def close_default():
|
||||||
|
global _default
|
||||||
|
log.info(__name__, 'close default %s', _default)
|
||||||
|
_default.close()
|
||||||
|
_default = None
|
||||||
|
|
||||||
|
|
||||||
def start_workflow(workflow):
|
def start_workflow(workflow):
|
||||||
global _default_workflow
|
if _default is not None:
|
||||||
if _default_workflow is not None:
|
close_default()
|
||||||
log.info(__name__, 'closing default workflow %s', _default_workflow)
|
_started.append(workflow)
|
||||||
_default_workflow.close()
|
log.info(__name__, 'start %s', workflow)
|
||||||
_default_workflow = None
|
loop.schedule_task(_watch_workflow(workflow))
|
||||||
|
|
||||||
log.info(__name__, 'starting workflow %s', workflow)
|
|
||||||
_started_workflows.append(workflow)
|
|
||||||
loop.schedule_task(watch_workflow(workflow))
|
|
||||||
|
|
||||||
|
|
||||||
async def watch_workflow(workflow):
|
async def _watch_workflow(workflow):
|
||||||
global _default_workflow
|
|
||||||
try:
|
try:
|
||||||
return await workflow
|
return await workflow
|
||||||
finally:
|
finally:
|
||||||
_started_workflows.remove(workflow)
|
_started.remove(workflow)
|
||||||
|
if not _started and _default_genfunc is not None:
|
||||||
if not _started_workflows and _default_workflow_genfunc is not None:
|
start_default(_default_genfunc)
|
||||||
start_default(_default_workflow_genfunc)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user