Class Task

Schedule the execution of a fiber: wrap it in a future. A task is a subclass of Future.

A task is responsible for executing a fiber object in an event loop. If the wrapped fiber yields from a future, the task suspends the execution of the wrapped fiber and waits for the completion of the future. When the future is done, the execution of the wrapped fiber restarts with the result or the exception of the fiber.

Event loops use cooperative scheduling: an event loop only runs one task at a time. Other tasks may run in parallel if other event loops are running in different threads. While a task waits for the completion of a future, the event loop executes a new task.

The cancellation of a task is different from the cancellation of a future. Calling cancel() will throw a CancelledException to the wrapped fiber. cancelled() only returns true if the wrapped fiber did not catch the CancelledException, or raised a CancelledException.

If a pending task is destroyed, the execution of its wrapped fiber did not complete. It is probably a bug and a warning is logged: see Pending task destroyed.

Don’t directly create Task instances: use the task() function or the EventLoop.create_task() method.

Inherits from

  • Object (base class)

Methods

Name Description
cancel Request that this task cancel itself.

Authors

Dragos Carp

Copyright

© 2015-2016 Dragos Carp

License

Boost Software License - Version 1.0