This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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