Skip to content

Instantly share code, notes, and snippets.

@lanfon72
Created May 17, 2017 15:51
Show Gist options
  • Select an option

  • Save lanfon72/e2298d4a82eaf897c40e798d9b77a19e to your computer and use it in GitHub Desktop.

Select an option

Save lanfon72/e2298d4a82eaf897c40e798d9b77a19e to your computer and use it in GitHub Desktop.
asyncio.callback
import asyncio
def q(val, fut):
print(val)
fut.set_result(val)
def cb(fut):
r = fut.result()
print(r, "world")
fut._loop.stop()
loop = asyncio.get_event_loop()
fut = loop.create_future()
fut.add_done_callback(cb)
loop.call_soon(q, "hello", fut)
loop.run_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment