mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-11 16:00:57 +00:00
core: remove loop.signal in favor of chan, change usage
This commit is contained in:
parent
f680f0c0d3
commit
741bfd5c53
@ -220,53 +220,6 @@ class wait(Syscall):
|
|||||||
pause(task, self.msg_iface)
|
pause(task, self.msg_iface)
|
||||||
|
|
||||||
|
|
||||||
_NO_VALUE = object()
|
|
||||||
|
|
||||||
|
|
||||||
class signal(Syscall):
|
|
||||||
"""
|
|
||||||
Pause current task, and let other running task to resume it later with a
|
|
||||||
result value or an exception.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
>>> # in task #1:
|
|
||||||
>>> signal = loop.signal()
|
|
||||||
>>> result = await signal
|
|
||||||
>>> print('awaited result:', result)
|
|
||||||
>>> # in task #2:
|
|
||||||
>>> signal.send('hello from task #2')
|
|
||||||
>>> # prints in the next iteration of the event loop
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self) -> None:
|
|
||||||
self.reset()
|
|
||||||
|
|
||||||
def reset(self) -> None:
|
|
||||||
self.value = _NO_VALUE
|
|
||||||
self.task = None # type: Optional[Task]
|
|
||||||
|
|
||||||
def handle(self, task: Task) -> None:
|
|
||||||
self.task = task
|
|
||||||
self._deliver()
|
|
||||||
|
|
||||||
def send(self, value: Any) -> None:
|
|
||||||
self.value = value
|
|
||||||
self._deliver()
|
|
||||||
|
|
||||||
def _deliver(self) -> None:
|
|
||||||
if self.task is not None and self.value is not _NO_VALUE:
|
|
||||||
schedule(self.task, self.value)
|
|
||||||
self.reset()
|
|
||||||
|
|
||||||
def __iter__(self) -> Task: # type: ignore
|
|
||||||
try:
|
|
||||||
return (yield self)
|
|
||||||
except: # noqa: E722
|
|
||||||
self.task = None
|
|
||||||
raise
|
|
||||||
|
|
||||||
|
|
||||||
_type_gen = type((lambda: (yield))())
|
_type_gen = type((lambda: (yield))())
|
||||||
|
|
||||||
|
|
||||||
|
@ -200,12 +200,12 @@ class Layout(Control):
|
|||||||
async def __iter__(self) -> ResultValue:
|
async def __iter__(self) -> ResultValue:
|
||||||
value = None
|
value = None
|
||||||
try:
|
try:
|
||||||
if workflow.layout_signal.task is not None:
|
if workflow.layout_signal.takers:
|
||||||
workflow.layout_signal.send(LayoutCancelled())
|
await workflow.layout_signal.put(LayoutCancelled())
|
||||||
workflow.onlayoutstart(self)
|
workflow.onlayoutstart(self)
|
||||||
while True:
|
while True:
|
||||||
layout_tasks = self.create_tasks()
|
layout_tasks = self.create_tasks()
|
||||||
await loop.spawn(workflow.layout_signal, *layout_tasks)
|
await loop.spawn(workflow.layout_signal.take, *layout_tasks)
|
||||||
except Result as result:
|
except Result as result:
|
||||||
value = result.value
|
value = result.value
|
||||||
finally:
|
finally:
|
||||||
|
@ -6,7 +6,7 @@ if False:
|
|||||||
|
|
||||||
workflows = [] # type: List[loop.Task]
|
workflows = [] # type: List[loop.Task]
|
||||||
layouts = [] # type: List[ui.Layout]
|
layouts = [] # type: List[ui.Layout]
|
||||||
layout_signal = loop.signal()
|
layout_signal = loop.chan()
|
||||||
default = None # type: Optional[loop.Task]
|
default = None # type: Optional[loop.Task]
|
||||||
default_layout = None # type: Optional[Callable[[], loop.Task]]
|
default_layout = None # type: Optional[Callable[[], loop.Task]]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user