mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-23 23:08:14 +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)
|
||||
|
||||
|
||||
_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))())
|
||||
|
||||
|
||||
|
@ -200,12 +200,12 @@ class Layout(Control):
|
||||
async def __iter__(self) -> ResultValue:
|
||||
value = None
|
||||
try:
|
||||
if workflow.layout_signal.task is not None:
|
||||
workflow.layout_signal.send(LayoutCancelled())
|
||||
if workflow.layout_signal.takers:
|
||||
await workflow.layout_signal.put(LayoutCancelled())
|
||||
workflow.onlayoutstart(self)
|
||||
while True:
|
||||
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:
|
||||
value = result.value
|
||||
finally:
|
||||
|
@ -6,7 +6,7 @@ if False:
|
||||
|
||||
workflows = [] # type: List[loop.Task]
|
||||
layouts = [] # type: List[ui.Layout]
|
||||
layout_signal = loop.signal()
|
||||
layout_signal = loop.chan()
|
||||
default = None # type: Optional[loop.Task]
|
||||
default_layout = None # type: Optional[Callable[[], loop.Task]]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user