Created
July 17, 2020 06:49
-
-
Save efenfauzi/9e9dcf72bf8cc09aa44552295f7309f4 to your computer and use it in GitHub Desktop.
2 function task in asyncio
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 | |
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