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 cancelation of a future.
Calling $(D_PSYMBOL cancel()) will throw a $(D_PSYMBOL CancelledException)
to the wrapped fiber. $(D_PSYMBOL cancelled()) only returns $(D_KEYWORD
true) if the wrapped fiber did not catch the $(D_PSYMBOL
CancelledException), or raised a $(D_PSYMBOL 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 $(D_PSYMBOL Task) instances: use the $(D_PSYMBOL
task()) function or the $(D_PSYMBOL EventLoop.create_task()) method.
class Task : Future!(ReturnType!Coroutine), TaskHandle (
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 cancelation of a future. Calling $(D_PSYMBOL cancel()) will throw a $(D_PSYMBOL CancelledException) to the wrapped fiber. $(D_PSYMBOL cancelled()) only returns $(D_KEYWORD true) if the wrapped fiber did not catch the $(D_PSYMBOL CancelledException), or raised a $(D_PSYMBOL 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 $(D_PSYMBOL Task) instances: use the $(D_PSYMBOL task()) function or the $(D_PSYMBOL EventLoop.create_task()) method.