OpenLexocad  27.1
entt::scheduler< Delta > Class Template Reference

Cooperative scheduler for processes. More...

#include <entt.hpp>

Public Types

using size_type = std::size_t
 Unsigned integer type. More...
 

Public Member Functions

 scheduler () ENTT_NOEXCEPT=default
 Default constructor. More...
 
 scheduler (scheduler &&)=default
 Default move constructor. More...
 
scheduleroperator= (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...
 

Detailed Description

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) {
// code
}).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
DeltaType to use to provide elapsed time.

Member Typedef Documentation

◆ size_type

template<typename Delta >
using entt::scheduler< Delta >::size_type = std::size_t

Unsigned integer type.

Constructor & Destructor Documentation

◆ scheduler() [1/2]

template<typename Delta >
entt::scheduler< Delta >::scheduler ( )
default

Default constructor.

◆ scheduler() [2/2]

template<typename Delta >
entt::scheduler< Delta >::scheduler ( scheduler< Delta > &&  )
default

Default move constructor.

Member Function Documentation

◆ abort()

template<typename Delta >
void entt::scheduler< Delta >::abort ( const bool  immediately = false)
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.

Parameters
immediatelyRequests an immediate operation.

◆ attach() [1/2]

template<typename Delta >
template<typename Proc , typename... Args>
auto entt::scheduler< Delta >::attach ( Args &&...  args)
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):

// schedules a task in the form of a process class
scheduler.attach<my_process>(arguments...)
// appends a child in the form of a lambda function
.then([](auto delta, void *, auto succeed, auto fail) {
// code
})
// appends a child in the form of another process class
.then<my_other_process>();
Template Parameters
ProcType of process to schedule.
ArgsTypes of arguments to use to initialize the process.
Parameters
argsParameters to use to initialize the process.
Returns
An opaque object to use to concatenate processes.

◆ attach() [2/2]

template<typename Delta >
template<typename Func >
auto entt::scheduler< Delta >::attach ( Func &&  func)
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:

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:

void();

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):

// schedules a task in the form of a lambda function
scheduler.attach([](auto delta, void *, auto succeed, auto fail) {
// code
})
// appends a child in the form of another lambda function
.then([](auto delta, void *, auto succeed, auto fail) {
// code
})
// appends a child in the form of a process class
.then<my_process>(arguments...);
See also
process_adaptor
Template Parameters
FuncType of process to schedule.
Parameters
funcEither a lambda or a functor to use as a process.
Returns
An opaque object to use to concatenate processes.

◆ clear()

template<typename Delta >
void entt::scheduler< Delta >::clear ( void  )
inline

Discards all scheduled processes.

Processes aren't aborted. They are discarded along with their children and never executed again.

◆ empty()

template<typename Delta >
bool entt::scheduler< Delta >::empty ( ) const
inline

Returns true if at least a process is currently scheduled.

Returns
True if there are scheduled processes, false otherwise.

◆ operator=()

template<typename Delta >
scheduler& entt::scheduler< Delta >::operator= ( scheduler< Delta > &&  )
default

Default move assignment operator.

Returns
This scheduler.

◆ size()

template<typename Delta >
size_type entt::scheduler< Delta >::size ( ) const
inline

Number of processes currently scheduled.

Returns
Number of processes currently scheduled.

◆ update()

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
deltaElapsed time.
dataOptional data.

The documentation for this class was generated from the following file: