extmod/uasyncio: Handle gather with no awaitables.

This previously resulted in gather() yielding but with no way to be
resumed.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
pull/8958/head^2
Jim Mussared 2022-07-21 09:54:02 +10:00 zatwierdzone przez Damien George
rodzic 092784da19
commit b22abcdbbe
3 zmienionych plików z 10 dodań i 0 usunięć

Wyświetl plik

@ -62,6 +62,9 @@ class _Remove:
async def gather(*aws, return_exceptions=False):
if not aws:
return []
def done(t, er):
# Sub-task "t" has finished, with exception "er".
nonlocal state

Wyświetl plik

@ -53,6 +53,11 @@ async def main():
print("====")
# Gather with no awaitables
print(await asyncio.gather())
print("====")
# Test return_exceptions, where one task is cancelled and the other finishes normally
tasks = [asyncio.create_task(task(1)), asyncio.create_task(task(2))]
tasks[0].cancel()

Wyświetl plik

@ -9,6 +9,8 @@ Task C: Compute factorial(4)...
Task C: factorial(4) = 24
[2, 6, 24]
====
[]
====
start 2
end 2
[CancelledError(), 2]