1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-04 13:38:28 +00:00
trezor-firmware/src/trezor/workflow.py

39 lines
860 B
Python
Raw Normal View History

from trezor import log, loop
2016-10-06 10:35:05 +00:00
_started = []
_default = None
_default_genfunc = None
def start_default(genfunc):
2016-10-06 10:35:05 +00:00
global _default
global _default_genfunc
_default_genfunc = genfunc
_default = _default_genfunc()
log.info(__name__, 'start default %s', _default)
loop.schedule_task(_default)
2016-10-06 10:35:05 +00:00
def close_default():
global _default
log.info(__name__, 'close default %s', _default)
_default.close()
_default = None
2016-12-08 15:18:58 +00:00
def start(workflow):
2016-10-06 10:35:05 +00:00
if _default is not None:
close_default()
_started.append(workflow)
log.info(__name__, 'start %s', workflow)
2016-12-08 15:18:58 +00:00
loop.schedule_task(_watch(workflow))
2016-12-08 15:18:58 +00:00
async def _watch(workflow):
try:
return await workflow
finally:
2016-10-06 10:35:05 +00:00
_started.remove(workflow)
if not _started and _default_genfunc is not None:
start_default(_default_genfunc)