Skip to content

Instantly share code, notes, and snippets.

@wufniks
Created August 11, 2021 09:48
Show Gist options
  • Save wufniks/f9a018c07cdbd487578ddb9707682e61 to your computer and use it in GitHub Desktop.
Save wufniks/f9a018c07cdbd487578ddb9707682e61 to your computer and use it in GitHub Desktop.
#!/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