|
RAVENNAKIT
|
A timer that uses boost::asio::steady_timer to provide a simple way of creating a timer without thinking about the lifetimes. More...
#include <asio_timer.hpp>
Public Types | |
| using | TimerCallback = std::function<void()> |
Public Member Functions | |
| AsioTimer (boost::asio::io_context &io_context) | |
| ~AsioTimer () | |
| void | once (std::chrono::milliseconds duration, TimerCallback cb) |
| Fires the callback once after the given duration. | |
| void | start (std::chrono::milliseconds duration, TimerCallback cb, bool repeating=true) |
| Fires the callback after the given duration. | |
| void | stop () |
| Stops the timer and cancels any pending callbacks. | |
A timer that uses boost::asio::steady_timer to provide a simple way of creating a timer without thinking about the lifetimes.
Definition at line 37 of file asio_timer.hpp.
| using rav::AsioTimer::TimerCallback = std::function<void()> |
Definition at line 39 of file asio_timer.hpp.
|
explicit |
| rav::AsioTimer::~AsioTimer | ( | ) |
| void rav::AsioTimer::once | ( | std::chrono::milliseconds | duration, |
| TimerCallback | cb ) |
Fires the callback once after the given duration.
The timer will be stopped before starting a new one.
| duration | The duration to wait before firing the callback. |
| cb | The callback to fire after the duration. |
| void rav::AsioTimer::start | ( | std::chrono::milliseconds | duration, |
| TimerCallback | cb, | ||
| bool | repeating = true ) |
Fires the callback after the given duration.
The callback will be fired repeatedly until stopped. The timer will be stopped before starting a new one. Safe to call from any thread.
| duration | The duration to wait before firing the callback. |
| cb | The callback to fire after the duration. |
| repeating | If true, the timer will repeat the callback after each duration. |
| void rav::AsioTimer::stop | ( | ) |
Stops the timer and cancels any pending callbacks.
After this call returns, no more callbacks will be fired. Can be called from any thread. The work is scheduled on the io_context thread.