Skip to content

Commit

Permalink
extmod/uasyncio: Handle gather with no awaitables.
Browse files Browse the repository at this point in the history
This previously resulted in gather() yielding but with no way to be
resumed.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
  • Loading branch information
jimmo authored and dpgeorge committed Jul 26, 2022
1 parent 092784d commit b22abcd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions extmod/uasyncio/funcs.py
Expand Up @@ -62,6 +62,9 @@ def remove(t):


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
Expand Down
5 changes: 5 additions & 0 deletions tests/extmod/uasyncio_gather.py
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions tests/extmod/uasyncio_gather.py.exp
Expand Up @@ -9,6 +9,8 @@ Task C: Compute factorial(4)...
Task C: factorial(4) = 24
[2, 6, 24]
====
[]
====
start 2
end 2
[CancelledError(), 2]
Expand Down

0 comments on commit b22abcd

Please sign in to comment.