1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-03 12:00:59 +00:00

loop: make it possible to re-use Future instances

This commit is contained in:
Jan Pochyla 2016-11-15 13:47:36 +01:00
parent abb6f284ca
commit 5d7c2ac4e2

View File

@ -144,17 +144,17 @@ class Future(Syscall):
def handle(self, task):
self.task = task
if self.value is not NO_VALUE:
self._deliver()
self._deliver()
def resolve(self, value):
if self.value is NO_VALUE:
self.value = value
if self.task is not None:
self._deliver()
self.value = value
self._deliver()
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):
@ -180,12 +180,9 @@ class Wait(Syscall):
unpause_task(task)
task.close()
def _wait(self, child):
async def _wait(self, child):
try:
if isinstance(child, type_gen):
result = yield from child
else:
result = yield child
result = await child
except Exception as e:
self._finish(child, e)
else: