template<typename Delta>
class entt::scheduler< Delta >
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):
scheduler.attach([](
auto delta,
void *,
auto succeed,
auto fail) {
}).then<my_process>(arguments...);
In order to invoke all scheduled processes, call the update
member function passing it the elapsed time to forward to the tasks.
- See also
- process
- Template Parameters
-
Delta | Type to use to provide elapsed time. |
template<typename Delta >
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.
- Parameters
-
immediately | Requests an immediate operation. |
template<typename Delta >
template<typename Proc , typename... Args>
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):
.then([](auto delta, void *, auto succeed, auto fail) {
})
.then<my_other_process>();
- Template Parameters
-
Proc | Type of process to schedule. |
Args | Types of arguments to use to initialize the process. |
- Parameters
-
args | Parameters to use to initialize the process. |
- Returns
- An opaque object to use to concatenate processes.
template<typename Delta >
template<typename Func >
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:
void(Delta delta, void *data, auto succeed, auto fail);
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):
scheduler.attach([](
auto delta,
void *,
auto succeed,
auto fail) {
})
.then([](auto delta, void *, auto succeed, auto fail) {
})
.then<my_process>(arguments...);
- See also
- process_adaptor
- Template Parameters
-
Func | Type of process to schedule. |
- Parameters
-
func | Either a lambda or a functor to use as a process. |
- Returns
- An opaque object to use to concatenate processes.
template<typename Delta >
void entt::scheduler< Delta >::update |
( |
const Delta |
delta, |
|
|
void * |
data = nullptr |
|
) |
| |
|
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.
- Parameters
-
delta | Elapsed time. |
data | Optional data. |