ExecutorThread is a wrapper of std::thread that calls a callback periodically.
More...
#include <aikido/common/ExecutorThread.hpp>
|
void | spin () |
| The loop function that will be executed by the thread. More...
|
|
ExecutorThread is a wrapper of std::thread that calls a callback periodically.
If you want to let ExecutorThread calls multiple callbacks then consider using ExecutorMultiplexer.
[]() { std::cout << "running...\n"; }, std::chrono::milliseconds(10));
- See also
- ExecutorMultiplexer
◆ ExecutorThread()
template<typename Duration >
aikido::common::ExecutorThread::ExecutorThread |
( |
std::function< void()> |
callback, |
|
|
const Duration & |
period |
|
) |
| |
Constructs from callback and period.
The thread begins execution immediately upon construction.
- Parameters
-
[in] | callback | Callback to be repeatedly executed by the thread. |
[in] | period | The period of calling the callback. |
◆ ~ExecutorThread()
aikido::common::ExecutorThread::~ExecutorThread |
( |
| ) |
|
◆ isRunning()
bool aikido::common::ExecutorThread::isRunning |
( |
| ) |
const |
Returns true if the thread is running.
◆ spin()
void aikido::common::ExecutorThread::spin |
( |
| ) |
|
|
private |
The loop function that will be executed by the thread.
◆ stop()
void aikido::common::ExecutorThread::stop |
( |
| ) |
|
Stops the thread.
It is safe to call this function even when the thread already stopped.
◆ mCallback
std::function<void()> aikido::common::ExecutorThread::mCallback |
|
private |
Callback to be periodically executed by the thread.
◆ mIsRunning
std::atomic<bool> aikido::common::ExecutorThread::mIsRunning |
|
private |
Flag whether the thread is running.
◆ mPeriod
std::chrono::milliseconds aikido::common::ExecutorThread::mPeriod |
|
private |
The callback is called in this period.
◆ mThread
std::thread aikido::common::ExecutorThread::mThread |
|
private |