Created
August 11, 2021 09:48
-
-
Save wufniks/f9a018c07cdbd487578ddb9707682e61 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
import asyncio | |
async def waiter(event): | |
print('waiting for it ...') | |
await event.wait() | |
print('... got it!') | |
async def main(): | |
# Create an Event object. | |
event = asyncio.Event() | |
for _ in range(100): | |
# Spawn a Task to wait until 'event' is set. | |
waiter_task = asyncio.create_task(waiter(event)) | |
# Sleep for 1 second and set the event. | |
await asyncio.sleep(1) | |
event.set() | |
# Wait until the waiter task is finished. | |
await waiter_task | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment