Nugget
|
A task queue for processing tasks sequentially. More...
#include <psyqo/task.hh>
Classes | |
class | Task |
The Task class. More... | |
Public Member Functions | |
void | reset () |
Resets the queue. | |
TaskQueue & | startWith (Task &&) |
Enqueues a task for execution. | |
TaskQueue & | startWith (eastl::function< void(Task *)> &&fun) |
TaskQueue & | then (Task &&) |
Enqueues a task for execution. | |
TaskQueue & | then (eastl::function< void(Task *)> &&fun) |
TaskQueue & | butCatch (eastl::function< void(TaskQueue *)> &&) |
Sets the exception handler. | |
TaskQueue & | finally (eastl::function< void(TaskQueue *)> &&) |
Sets the finally handler. | |
void | run () |
Runs the task queue. | |
Task | schedule () |
Schedules the task queue to another task queue. | |
bool | isRunning () const |
Queries the status of the queue. | |
Static Public Member Functions | |
static Task | DelayedTask (uint32_t delay, GPU &) |
Creates a delayed task. | |
Friends | |
class | Task |
A task queue for processing tasks sequentially.
This class is used to process a sequence of tasks one after the other. The design is loosely inspired by the JavaScript Promise API. A task is effectively a lambda function. A queue can be run multiple times, and can also be embedded within another queue.
psyqo::TaskQueue & psyqo::TaskQueue::butCatch | ( | eastl::function< void(TaskQueue *)> && | fun | ) |
Sets the exception handler.
This method will set the exception handler. The exception handler will be called if any of the tasks in the queue throws an exception. The exception handler will be called with the task queue as its argument. Calling this while the queue is running is undefined behavior.
|
static |
Creates a delayed task.
This method is a convenience method to create a task that will be executed after a delay. The delay is specified in microseconds.
delay | The delay in microseconds. |
psyqo::TaskQueue & psyqo::TaskQueue::finally | ( | eastl::function< void(TaskQueue *)> && | fun | ) |
Sets the finally handler.
This method will set the finally handler. The finally handler will be called after all tasks in the queue have been executed, or after the exception handler. The finally handler will be called with the task queue as its argument. Calling this while the queue is running is undefined behavior.
|
inline |
Queries the status of the queue.
void psyqo::TaskQueue::reset | ( | ) |
Resets the queue.
This method resets the queue to its initial state. Calling this method while the queue is running is undefined behavior.
void psyqo::TaskQueue::run | ( | ) |
Runs the task queue.
This method will start running the queue. The queue will continue to run until all tasks have been executed, or until an exception is thrown. This method can be called multiple times, in order to execute the whole queue multiple times. Calling this while the queue is already running is undefined behavior.
psyqo::TaskQueue::Task psyqo::TaskQueue::schedule | ( | ) |
Schedules the task queue to another task queue.
This method will enable embedding the queue into another one. Exceptions will be cascading.
psyqo::TaskQueue & psyqo::TaskQueue::startWith | ( | Task && | task | ) |
Enqueues a task for execution.
This method will enqueue a task for execution, while resetting the queue first. This means that any previously enqueued tasks will be removed first. Any exception handler or finally handler will also be cleared out. Calling this while the queue is running is undefined behavior.
psyqo::TaskQueue & psyqo::TaskQueue::then | ( | Task && | task | ) |
Enqueues a task for execution.
This method will enqueue a task for execution. The task will be executed after all previously enqueued tasks have been executed. Calling this while the queue is running is undefined behavior.
|
friend |