Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
async def with_item_timeout(aiter, timeout):
aiter = aiter.__aiter__()
while True:
with trio.move_on_after(timeout) as cscope:
try:
val = await aiter.__anext__()
except StopAsyncIteration:
return
if cscope.cancelled_caught:
print("cancelled")
return
yield val
async for val in with_item_timeout(some_async_iterable):
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment