Skip to content

Instantly share code, notes, and snippets.

@narenaryan
Created January 6, 2022 17:19
Show Gist options
  • Select an option

  • Save narenaryan/920ec78d22c3a7174aac063034217708 to your computer and use it in GitHub Desktop.

Select an option

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