Open this example in the interactive library
Source code
import asyncio
async def stream():
for n in range(3):
yield n
async def main():
return [n async for n in stream()]
print(asyncio.run(main()))Sample output
[0, 1, 2]

Consume an async generator. A self-contained example using the Python standard library.
Open this example in the interactive library
import asyncio
async def stream():
for n in range(3):
yield n
async def main():
return [n async for n in stream()]
print(asyncio.run(main()))[0, 1, 2]