Skip to content

Instantly share code, notes, and snippets.

@efenfauzi
Created July 17, 2020 06:49
Show Gist options
  • Save efenfauzi/9e9dcf72bf8cc09aa44552295f7309f4 to your computer and use it in GitHub Desktop.
Save efenfauzi/9e9dcf72bf8cc09aa44552295f7309f4 to your computer and use it in GitHub Desktop.
2 function task in asyncio
import asyncio
async def function1(delay):
await asyncio.sleep(delay)
print ("Function 1 Task")
async def function2(delay):
await asyncio.sleep(delay)
print ("Function 2 Task")
async def do_task():
task_1 = asyncio.create_task(function1(1))
task_2 = asyncio.create_task(function2(5))
for i in range(3):
await task_1
print ("do task 1")
await task_2
print ("do_task 2")
asyncio.run(do_task())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment