Dev Helpers
← Back

Gather concurrent results

Gather concurrent results. A self-contained example using the Python standard library.

Open this example in the interactive library

Source code

import asyncio
async def double(n):
    await asyncio.sleep(0)
    return n * 2
async def main():
    return await asyncio.gather(*(double(n) for n in range(3)))
print(asyncio.run(main()))

Sample output

[0, 2, 4]