Created
January 6, 2022 17:19
-
-
Save narenaryan/920ec78d22c3a7174aac063034217708 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
| import asyncio | |
| # A co-routine | |
| async def add(x: int, y: int): | |
| return x + y | |
| # An event loop | |
| loop = asyncio.get_event_loop() | |
| # Execute two co-routines | |
| result1 = loop.run_until_complete(add(3, 4)) | |
| result2 = loop.run_until_complete(add(5, 5)) | |
| print(result1) # Prints 7 | |
| print(result2) # Prints 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment