Async 1.8.0
|
Run tasks from the Async main thread with automatic cleanup. More...
#include <AsyncTaskRunner.h>
Public Member Functions | |
TaskRunner (void) | |
Default constructor. | |
TaskRunner (const TaskRunner &)=delete | |
Copy constructor is deleted. | |
~TaskRunner (void) | |
Destructor. | |
TaskRunner & | operator= (const TaskRunner &)=delete |
Assignment operator is deleted. | |
template<typename TaskHandler > | |
Application::TaskId | operator() (TaskHandler &&handler) |
Run a task from the Async main loop. | |
template<typename Func , typename Arg1 , typename... Args> | |
Application::TaskId | operator() (Func &&f, Arg1 &&arg1, Args &&... args) |
Run a task from the Async main loop. | |
void | cancel (void) |
Cancel all queued tasks for this object. | |
Run tasks from the Async main thread with automatic cleanup.
This class is used to run delayed tasks from the Async main thread. If the object is destroyed before the task has been executed all tasks queued by this object are cancelled. That property is the main advantage for using this class rather than calling the Application::runTask functions directly.
A TaskRunner is typically used to break up long callback chains or to run a task on the main Async threa when running in another thread.
Definition at line 124 of file AsyncTaskRunner.h.
|
inline |
Default constructor.
Definition at line 130 of file AsyncTaskRunner.h.
|
delete |
Copy constructor is deleted.
|
inline |
Destructor.
Will cancel all pending tasks
Definition at line 142 of file AsyncTaskRunner.h.
References cancel().
|
inline |
Cancel all queued tasks for this object.
Definition at line 230 of file AsyncTaskRunner.h.
References Async::Application::app().
Referenced by ~TaskRunner(), and Async::ThreadSigCSignal< T_ret, Args >::~ThreadSigCSignal().
|
inline |
Run a task from the Async main loop.
f | The function to call |
arg1 | The first argument to the function |
args | The rest of the arguments to the function |
This overloaded function is used if more than one argument is used in the function call. Calling a function taking two arguments can look like this:
runTask(&the_function, true, 42);
For a member function the second argument must be the object pointer so the syntax for a member function taking two arguments would look something like this:
runTask(&MyClass::func, this, true, 42);
This function is thread safe so a separate thread can add tasks which are then executed on the main Async thread.
Definition at line 221 of file AsyncTaskRunner.h.
References Async::Application::app(), and Async::Application::runTask().
|
inline |
Run a task from the Async main loop.
handler | The handler function for the task to run |
Use it like this to call a normal function taking no arguments:
myTaskRunnerInstance(&the_function);
If the function takes arguments, you need to use std::bind but then it's better to use the other version of this function which calls bind for you. But anyway, with std::bind it will look something like this for a function taking a bool and an int as arguments:
myTaskRunnerInstance(std::bind(&the_function, true, 42));
For a member function the second argument to std::bind must be the object pointer so the syntax for a member function taking two arguments would look something like this:
myTaskRunnerInstance(std::bind(&MyClass::func, this, true, 42));
This function is thread safe so a separate thread can add tasks which are then executed on the main Async thread.
Definition at line 192 of file AsyncTaskRunner.h.
References Async::Application::app(), and Async::Application::runTask().
|
delete |
Assignment operator is deleted.