1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 01:18:28 +00:00

overload __iter__ in loop.Wait

This will automatically exit child tasks in case of close() or throw() on the waiting task, but only if run through `await` or `yield from`
This commit is contained in:
Jan Pochyla 2016-09-25 15:55:08 +02:00 committed by Pavol Rusnak
parent 02b13af526
commit 70110187cc
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 8 additions and 5 deletions

View File

@ -15,8 +15,4 @@ async def animate_logo():
async def layout_homescreen():
wait = loop.Wait([swipe_to_rotate(), animate_logo()])
try:
await wait
finally:
wait.exit()
await loop.Wait([swipe_to_rotate(), animate_logo()])

View File

@ -194,3 +194,10 @@ class Wait(Syscall):
if self.exit_others:
self.exit()
schedule_task(self.callback, result)
def __iter__(self):
try:
return (yield self)
except:
self.exit()
raise