26 lines
564 B
Python
26 lines
564 B
Python
import asyncio
|
|
|
|
|
|
async def test_cor_1(future: asyncio.Future):
|
|
print("cor_1 started")
|
|
await asyncio.sleep(2)
|
|
print("cor_1 set future result to 100")
|
|
future.set_result(100)
|
|
print("cor_1 continue to sleep")
|
|
await asyncio.sleep(2)
|
|
print("cor_1 finished")
|
|
|
|
|
|
async def test_cor_2():
|
|
print("cor_2 executed")
|
|
|
|
|
|
async def main():
|
|
future = asyncio.Future()
|
|
tasks = []
|
|
tasks.append(asyncio.create_task(test_cor_1(future)))
|
|
tasks.append(asyncio.create_task(test_cor_2()))
|
|
await asyncio.gather(*tasks)
|
|
|
|
|
|
asyncio.run(main())
|