Clementine
|
Cooperative scheduler for processes. More...
#include <entt.hpp>
Public Types | |
using | size_type = std::size_t |
Unsigned integer type. | |
Public Member Functions | |
scheduler ()=default | |
Default constructor. | |
scheduler (scheduler &&)=default | |
Default move constructor. | |
scheduler & | operator= (scheduler &&)=default |
Default move assignment operator. More... | |
size_type | size () const ENTT_NOEXCEPT |
Number of processes currently scheduled. More... | |
bool | empty () const ENTT_NOEXCEPT |
Returns true if at least a process is currently scheduled. More... | |
void | clear () |
Discards all scheduled processes. More... | |
template<typename Proc , typename... Args> | |
auto | attach (Args &&... args) |
Schedules a process for the next tick. More... | |
template<typename Func > | |
auto | attach (Func &&func) |
Schedules a process for the next tick. More... | |
void | update (const Delta delta, void *data=nullptr) |
Updates all scheduled processes. More... | |
void | abort (const bool immediately=false) |
Aborts all scheduled processes. More... | |
Cooperative scheduler for processes.
A cooperative scheduler runs processes and helps managing their life cycles.
Each process is invoked once per tick. If a process terminates, it's removed automatically from the scheduler and it's never invoked again.
A process can also have a child. In this case, the process is replaced with its child when it terminates if it returns with success. In case of errors, both the process and its child are discarded.
Example of use (pseudocode):
In order to invoke all scheduled processes, call the update
member function passing it the elapsed time to forward to the tasks.
Delta | Type to use to provide elapsed time. |
|
inline |
Aborts all scheduled processes.
Unless an immediate operation is requested, the abort is scheduled for the next tick. Processes won't be executed anymore in any case.
Once a process is fully aborted and thus finished, it's discarded along with its child, if any.
immediately | Requests an immediate operation. |
|
inline |
Schedules a process for the next tick.
Returned value is an opaque object that can be used to attach a child to the given process. The child is automatically scheduled when the process terminates and only if the process returns with success.
Example of use (pseudocode):
Proc | Type of process to schedule. |
Args | Types of arguments to use to initialize the process. |
args | Parameters to use to initialize the process. |
|
inline |
Schedules a process for the next tick.
A process can be either a lambda or a functor. The scheduler wraps both of them in a process adaptor internally.
The signature of the function call operator should be equivalent to the following:
Where:
delta
is the elapsed time.data
is an opaque pointer to user data if any, nullptr
otherwise.succeed
is a function to call when a process terminates with success.fail
is a function to call when a process terminates with errors.The signature of the function call operator of both succeed
and fail
is equivalent to the following:
Returned value is an opaque object that can be used to attach a child to the given process. The child is automatically scheduled when the process terminates and only if the process returns with success.
Example of use (pseudocode):
Func | Type of process to schedule. |
func | Either a lambda or a functor to use as a process. |
|
inline |
Discards all scheduled processes.
Processes aren't aborted. They are discarded along with their children and never executed again.
|
inline |
Returns true if at least a process is currently scheduled.
|
default |
Default move assignment operator.
|
inline |
Number of processes currently scheduled.
|
inline |
Updates all scheduled processes.
All scheduled processes are executed in no specific order.
If a process terminates with success, it's replaced with its child, if any. Otherwise, if a process terminates with an error, it's removed along with its child.
delta | Elapsed time. |
data | Optional data. |