Skip to content

Instantly share code, notes, and snippets.

@singulared
Last active June 19, 2017 13:52
Show Gist options
  • Save singulared/a660b20937ff2f87a157c33640722ac2 to your computer and use it in GitHub Desktop.
Save singulared/a660b20937ff2f87a157c33640722ac2 to your computer and use it in GitHub Desktop.
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