class executor
Defined at line 1493 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h
An abstract interface for executing asynchronous tasks, such as promises,
represented by |fpromise::pending_task|.
EXECUTING TASKS
An executor evaluates its tasks incrementally. During each iteration
of the executor's main loop, it invokes the next task from its ready queue.
If the task returns true, then the task is deemed to have completed.
The executor removes the tasks from its queue and destroys it since there
it nothing left to do.
If the task returns false, then the task is deemed to have voluntarily
suspended itself pending some event that it is awaiting. Prior to
returning, the task should acquire at least one |fpromise::suspended_task|
handle from its execution context using |fpromise::context::suspend_task()|
to provide a means for the task to be resumed once it can make forward
progress again.
Once the suspended task is resumed with |fpromise::suspended_task::resume()|, it
is moved back to the ready queue and it will be invoked again during a later
iteration of the executor's loop.
If all |fpromise::suspended_task| handles for a given task are destroyed without
the task ever being resumed then the task is also destroyed since there
would be no way for the task to be resumed from suspension. We say that
such a task has been "abandoned".
The executor retains single-ownership of all active and suspended tasks.
When the executor is destroyed, all of its remaining tasks are also
destroyed.
Please read |fpromise::promise| for a more detailed explanation of the
responsibilities of tasks and executors.
NOTES FOR IMPLEMENTORS
This interface is designed to support a variety of different executor
implementations. For example, one implementation might run its tasks on
a single thread whereas another might dispatch them on an event-driven
message loop or use a thread pool.
See also |fpromise::single_threaded_executor| for a concrete implementation.
Public Methods
void schedule_task (pending_task task)
Schedules a task for eventual execution by the executor.
This method is thread-safe.
void ~executor ()
Destroys the executor along with all of its remaining scheduled tasks
that have yet to complete.
Defined at line 1497 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h