Skip to content

Instantly share code, notes, and snippets.

@DBoyara
Created July 5, 2021 05:33
Show Gist options
  • Select an option

  • Save DBoyara/e12017f864ebb331adfdb39b8bb1a306 to your computer and use it in GitHub Desktop.

Select an option

Save DBoyara/e12017f864ebb331adfdb39b8bb1a306 to your computer and use it in GitHub Desktop.
Async generator
import asyncio
async def ticker(delay, to):
for i in range(to):
yield i
await asyncio.sleep(delay)
async def run():
async for i in ticker(1, 10):
print(i)
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(run())
finally:
loop.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment