Last active
January 6, 2022 19:33
-
-
Save narenaryan/09ebbb4842d69891b058fce97015808c 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 | |
| # Create a function to schedule co-routines on the event loop | |
| # then print results and stop the loop | |
| async def get_results(): | |
| result1 = await add(3, 4) | |
| result2 = await add(5, 5) | |
| print(result1, result2) # Prints 7 10 | |
| asyncio.run(get_results()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment