Last active
June 19, 2017 13:52
-
-
Save singulared/a660b20937ff2f87a157c33640722ac2 to your computer and use it in GitHub Desktop.
This file contains 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 | |
from asyncio.futures import Future | |
loop = asyncio.get_event_loop() | |
async def wait_for_result(fut): | |
await asyncio.sleep(5) | |
fut.set_result('result') | |
async def tick(): | |
for i in range(5): | |
print('-', i, '-') | |
await asyncio.sleep(1) | |
async def main(loop): | |
future = Future(loop=loop) | |
asyncio.ensure_future(wait_for_result(future), loop=loop) | |
asyncio.ensure_future(tick(), loop=loop) | |
await future | |
print(future.result()) | |
loop.run_until_complete(main(loop)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment