22 lines
548 B
Python
22 lines
548 B
Python
import asyncio
|
|
|
|
|
|
async def waiter(future: asyncio.Future):
|
|
await future
|
|
print(
|
|
f"future выполнен, результат {future.result()}. Корутина waiter() может продолжить работу"
|
|
)
|
|
|
|
|
|
async def setter(future: asyncio.Future):
|
|
await asyncio.sleep(random.randint(1, 3))
|
|
future.set_result(True)
|
|
|
|
|
|
async def main():
|
|
future = asyncio.Future()
|
|
tasks = [asyncio.create_task(waiter(future)), asyncio.create_task(setter(future))]
|
|
await asyncio.gather(*tasks)
|
|
|
|
|
|
asyncio.run(main())
|