Created
July 5, 2021 05:33
-
-
Save DBoyara/e12017f864ebb331adfdb39b8bb1a306 to your computer and use it in GitHub Desktop.
Async generator
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 | |
| 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