Skip to content

Instantly share code, notes, and snippets.

@whatvn
Created November 14, 2016 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatvn/5f5fc0c6c1f3e9a18725c253e59b74ea to your computer and use it in GitHub Desktop.
Save whatvn/5f5fc0c6c1f3e9a18725c253e59b74ea to your computer and use it in GitHub Desktop.
import asyncio
class asyncOp(object):
def __init__(self, op, callback):
self.op = op
self.loop = asyncio.get_event_loop()
self.task = self.loop.create_task(self.op)
self.task.add_done_callback(callback)
def run(self):
self.loop.run_until_complete(self.task)
async def slow_operation():
await asyncio.sleep(1)
# our task is done, here's the result
return 'I am bmi master!'
def got_result(future):
print(future.result())
if __name__ == '__main__':
myOp = asyncOp(slow_operation(), got_result)
myOp.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment