Guest User

Untitled

a guest
Aug 23rd, 2019
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. import asyncio
  2.  
  3. task = None
  4.  
  5. def do_stuff(on_finished):
  6.     result = 5 + 5
  7.     asyncio.create_task(on_finished(result))
  8.  
  9.  
  10. def on_finished(result):
  11.     print("on_finished called")
  12.     async def actual_work():
  13.         await asyncio.sleep(0.1)
  14.         print(result)
  15.     return actual_work()
  16.  
  17.  
  18. async def main():
  19.     do_stuff(on_finished)
  20.     print("do_stuff exited")
  21.     await asyncio.sleep(0.2)
  22.  
  23.  
  24. if __name__ == "__main__":
  25.     asyncio.run(main())
Advertisement
Add Comment
Please, Sign In to add comment