Last active
May 9, 2024 23:09
-
-
Save normanlmfung/e5498e4ebbf5dc51fe880ff45542887d to your computer and use it in GitHub Desktop.
asyncio_gather_example
This file contains hidden or 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
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