Skip to content

Commit f1bfafc

Browse files
committed
Handle errors in an async generator.
1 parent 623dbb1 commit f1bfafc

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

trio_asyncio/util.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@ async def run_generator(loop, async_generator):
6060
async def consume_next():
6161
try:
6262
item = await async_generator.__anext__()
63+
result = trio.hazmat.Value(value=item)
6364
except StopAsyncIteration:
64-
item = STOP
65+
result = trio.hazmat.Value(value=STOP)
66+
except Exception as e:
67+
result = trio.hazmat.Error(error=e)
6568

66-
trio.hazmat.reschedule(task, trio.hazmat.Value(value=item))
67-
#trio.hazmat.reschedule(task, STOP)
69+
trio.hazmat.reschedule(task, result)
6870

6971
def abort_cb(raise_cancel_arg):
7072
# Save the cancel-raising function

0 commit comments

Comments
 (0)