Skip to content

Instantly share code, notes, and snippets.

@narenaryan
Last active January 6, 2022 19:33
Show Gist options
  • Select an option

  • Save narenaryan/09ebbb4842d69891b058fce97015808c to your computer and use it in GitHub Desktop.

Select an option

Save narenaryan/09ebbb4842d69891b058fce97015808c to your computer and use it in GitHub Desktop.
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