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 $(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.

Constructors

this
this(EventLoop eventLoop, Coroutine coroutine, Args args)
Undocumented in source.

Members

Aliases

ResultType
alias ResultType = ReturnType!Coroutine
Undocumented in source.

Functions

cancel
bool cancel()

Request that this task cancel itself.

id
string id()
Undocumented in source. Be warned that the author may not have intended to support it.
run
void run()
Undocumented in source. Be warned that the author may not have intended to support it.
scheduleStepImpl
void scheduleStepImpl(Throwable throwable)
Undocumented in source. Be warned that the author may not have intended to support it.
toString
string toString()
Undocumented in source. Be warned that the author may not have intended to support it.

Properties

injectException
Throwable injectException [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.

Variables

fiber
TaskFiber fiber;
Undocumented in source.

Inherited Members

From TaskHandle

injectException
Throwable injectException [@property getter]
Undocumented in source.
run
void run()
Undocumented in source.
scheduleStep
void scheduleStep()
Undocumented in source. Be warned that the author may not have intended to support it.
scheduleStep
void scheduleStep(Throwable throwable)
Undocumented in source. Be warned that the author may not have intended to support it.
scheduleStep
void scheduleStep(FutureHandle future)
Undocumented in source. Be warned that the author may not have intended to support it.
scheduleStepImpl
void scheduleStepImpl(Throwable throwable)
Undocumented in source.
allTasks
TaskHandle[] allTasks(EventLoop eventLoop)
currentTask
TaskHandle currentTask(EventLoop eventLoop)
getThis
TaskHandle getThis()
Undocumented in source. Be warned that the author may not have intended to support it.
yield
void yield()

Forces a context switch to occur away from the calling task.

Meta