Overview:
-
The add_done_callback() method adds a callback function to an asyncio.Task object which is called when the Task is done.
-
The task object itself is sent back to the call back through the context parameter.
Example:
# Example Python program that adds a completion # Callback - context object is the actual # A simple Python coroutine # Create an asyncio.Task object # Execute the task |
Output:
Task completion received... Name of the task:Task-2 Wrapped coroutine object:<coroutine object simple_coroutine at 0x106981540> Task is done:True Task has been cancelled:False Task result:1 <class '_asyncio.Task'> <Task finished name='Task-2' coro=<simple_coroutine() done, defined at /ex/example.py:19> result=1> Coroutine main() exiting |