Skip to content

Instantly share code, notes, and snippets.

@normanlmfung
Last active May 9, 2024 23:09
Show Gist options
  • Save normanlmfung/e5498e4ebbf5dc51fe880ff45542887d to your computer and use it in GitHub Desktop.
Save normanlmfung/e5498e4ebbf5dc51fe880ff45542887d to your computer and use it in GitHub Desktop.
asyncio_gather_example
import asyncio
import random
async def generate_random_int():
await asyncio.sleep(1) # Simulating some asynchronous task
return random.randint(1, 100)
async def main():
results = await asyncio.gather(generate_random_int(), generate_random_int())
print("Results:", results)
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment