TaskRunner
[Task](icy-Task.html#task) interface.TaskRunner
#include <icy/task.h>Runner for tasks that inherit the [Task](icy-Task.html#task) interface.
The [TaskRunner](#taskrunner) continually loops through each task in the task list calling the task's [run()](#run-6) method.
The [TaskRunner](#taskrunner) is powered by an abstract [Runner](icy-Runner.html#runner) instance, which means that tasks can be executed in a thread or event loop context.
Public Attributes
| Return | Name | Description |
|---|---|---|
NullSignal | Idle | Fires after completing an iteration of all tasks. |
NullSignal | Shutdown | Signals when the [TaskRunner](#taskrunner) is shutting down. |
Idle
NullSignal IdleFires after completing an iteration of all tasks.
Shutdown
NullSignal ShutdownSignals when the [TaskRunner](#taskrunner) is shutting down.
Public Methods
| Return | Name | Description |
|---|---|---|
TaskRunner | #### Parameters | |
TaskRunner | Deleted constructor. | |
TaskRunner | Deleted constructor. | |
bool | start virtual | Starts a task, adding it if it doesn't exist. |
bool | cancel virtual | Cancels a task. |
bool | destroy virtual | Queues a task for destruction. |
bool | exists virtual const | Returns whether a task exists. |
Task * | get virtual const | Returns the task pointer matching the given ID, or nullptr if no task exists. |
void | setRunner virtual | Set the asynchronous context for packet processing. This may be a Thread or another derivative of Async. Must be set before the stream is activated. |
const char * | className virtual const inline |
TaskRunner
TaskRunner(std::shared_ptr< Runner > runner)Parameters
runnerAsync runner to drive task execution; defaults to a new[Thread](icy-Thread.html#thread).
TaskRunner
TaskRunner(const TaskRunner &) = deleteDeleted constructor.
TaskRunner
TaskRunner(TaskRunner &&) = deleteDeleted constructor.
start
virtual
virtual bool start(Task * task)Starts a task, adding it if it doesn't exist.
cancel
virtual
virtual bool cancel(Task * task)Cancels a task.
The task reference will be managed by the TaskRunner until the task is destroyed.
destroy
virtual
virtual bool destroy(Task * task)Queues a task for destruction.
exists
virtual const
virtual bool exists(Task * task) constReturns whether a task exists.
get
virtual const
virtual Task * get(uint32_t id) constReturns the task pointer matching the given ID, or nullptr if no task exists.
setRunner
virtual
virtual void setRunner(std::shared_ptr< Runner > runner)Set the asynchronous context for packet processing. This may be a Thread or another derivative of Async. Must be set before the stream is activated.
className
virtual const inline
virtual inline const char * className() constPublic Static Methods
| Return | Name | Description |
|---|---|---|
TaskRunner & | getDefault static | Returns the default [TaskRunner](#taskrunner) singleton, although TaskRunner instances may be initialized individually. The default runner should be kept for short running tasks such as timers in order to maintain performance. |
getDefault
static
static TaskRunner & getDefault()Returns the default [TaskRunner](#taskrunner) singleton, although TaskRunner instances may be initialized individually. The default runner should be kept for short running tasks such as timers in order to maintain performance.
Protected Attributes
_mutex
std::mutex _mutex_runner
std::shared_ptr< Runner > _runner_tasks
TaskList _tasksProtected Methods
| Return | Name | Description |
|---|---|---|
void | run virtual | Called by the async context to run the next task. |
bool | add virtual | Adds a task to the runner. |
bool | remove virtual | Removes a task from the runner. |
Task * | next virtual const | Returns the next task to be run. |
void | clear virtual | Destroys and clears all manages tasks. |
void | onAdd virtual | Called after a task is added. |
void | onStart virtual | Called after a task is started. |
void | onCancel virtual | Called after a task is cancelled. |
void | onRemove virtual | Called after a task is removed. |
void | onRun virtual | Called after a task has run. |
run
virtual
virtual void run()Called by the async context to run the next task.
add
virtual
virtual bool add(Task * task)Adds a task to the runner.
remove
virtual
virtual bool remove(Task * task)Removes a task from the runner.
next
virtual const
virtual Task * next() constReturns the next task to be run.
clear
virtual
virtual void clear()Destroys and clears all manages tasks.
onAdd
virtual
virtual void onAdd(Task * task)Called after a task is added.
onStart
virtual
virtual void onStart(Task * task)Called after a task is started.
onCancel
virtual
virtual void onCancel(Task * task)Called after a task is cancelled.
onRemove
virtual
virtual void onRemove(Task * task)Called after a task is removed.
onRun
virtual
virtual void onRun(Task * task)Called after a task has run.
