Код: Выделить всё
import asyncio as aio
async def coro(future: aio.Future):
print('Coro start')
await aio.sleep(3)
print('Coro finish')
future.set_result('coro result')
async def main():
future = aio.Future()
aio.create_task(coro(future))
await future
coro_result = future.result()
print(coro_result)
aio.run(main())
Если я реорганизую свой main() вот так:
Код: Выделить всё
import asyncio as aio
async def coro(future: aio.Future):
print('Coro start')
await aio.sleep(3)
print('Coro finish')
future.set_result('coro result')
async def main():
future = aio.Future()
await aio.create_task(coro(future))
# await future
coro_result = future.result()
print(coro_result)
aio.run(main())
Подробнее здесь: https://stackoverflow.com/questions/793 ... re-objects