mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-20 12:21:01 +00:00
loop: make it possible to re-use Future instances
This commit is contained in:
parent
abb6f284ca
commit
5d7c2ac4e2
@ -144,17 +144,17 @@ class Future(Syscall):
|
|||||||
|
|
||||||
def handle(self, task):
|
def handle(self, task):
|
||||||
self.task = task
|
self.task = task
|
||||||
if self.value is not NO_VALUE:
|
self._deliver()
|
||||||
self._deliver()
|
|
||||||
|
|
||||||
def resolve(self, value):
|
def resolve(self, value):
|
||||||
if self.value is NO_VALUE:
|
self.value = value
|
||||||
self.value = value
|
self._deliver()
|
||||||
if self.task is not None:
|
|
||||||
self._deliver()
|
|
||||||
|
|
||||||
def _deliver(self):
|
def _deliver(self):
|
||||||
schedule_task(self.task, self.value)
|
if self.task is not None and self.value is not NO_VALUE:
|
||||||
|
schedule_task(self.task, self.value)
|
||||||
|
self.task = None
|
||||||
|
self.value = NO_VALUE
|
||||||
|
|
||||||
|
|
||||||
class Wait(Syscall):
|
class Wait(Syscall):
|
||||||
@ -180,12 +180,9 @@ class Wait(Syscall):
|
|||||||
unpause_task(task)
|
unpause_task(task)
|
||||||
task.close()
|
task.close()
|
||||||
|
|
||||||
def _wait(self, child):
|
async def _wait(self, child):
|
||||||
try:
|
try:
|
||||||
if isinstance(child, type_gen):
|
result = await child
|
||||||
result = yield from child
|
|
||||||
else:
|
|
||||||
result = yield child
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._finish(child, e)
|
self._finish(child, e)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user