Skip to content

Commit b22abcd

Browse files
jimmodpgeorge
authored andcommitted
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>
1 parent 092784d commit b22abcd

3 files changed

Lines changed: 10 additions & 0 deletions

File tree

extmod/uasyncio/funcs.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ def remove(t):
6262

6363

6464
async def gather(*aws, return_exceptions=False):
65+
if not aws:
66+
return []
67+
6568
def done(t, er):
6669
# Sub-task "t" has finished, with exception "er".
6770
nonlocal state

tests/extmod/uasyncio_gather.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ async def main():
5353

5454
print("====")
5555

56+
# Gather with no awaitables
57+
print(await asyncio.gather())
58+
59+
print("====")
60+
5661
# Test return_exceptions, where one task is cancelled and the other finishes normally
5762
tasks = [asyncio.create_task(task(1)), asyncio.create_task(task(2))]
5863
tasks[0].cancel()

tests/extmod/uasyncio_gather.py.exp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Task C: Compute factorial(4)...
99
Task C: factorial(4) = 24
1010
[2, 6, 24]
1111
====
12+
[]
13+
====
1214
start 2
1315
end 2
1416
[CancelledError(), 2]

0 commit comments

Comments
 (0)