Skip to content

Instantly share code, notes, and snippets.

@whatvn
Created November 14, 2016 10:23
Show Gist options
  • Save whatvn/71bccd2579137c3fbe341289b8c68800 to your computer and use it in GitHub Desktop.
Save whatvn/71bccd2579137c3fbe341289b8c68800 to your computer and use it in GitHub Desktop.
import asyncio
class asyncOp(object):
def __init__(self, loop):
self.loop = asyncio.get_event_loop()
def run(self, op, callback):
task = self.loop.create_task(op)
task.add_done_callback(callback)
self.loop.run_until_complete(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__':
loop = asyncio.get_event_loop()
myOp = asyncOp(loop)
myOp.run(slow_operation(), got_result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment