|
Periodic Timer
|
Public Types | |
| using | duration = typename Clock::duration |
| using | time_point = typename Clock::time_point |
Public Member Functions | |
| periodic_timer (asio::io_context &ioc) noexcept | |
| periodic_timer (const periodic_timer &)=delete | |
| periodic_timer & | operator= (const periodic_timer &)=delete |
| periodic_timer (periodic_timer &&)=default | |
| periodic_timer & | operator= (periodic_timer &&rhs) |
| template<typename F > | |
| void | start_duration_timer (const duration &dur, F &&func) |
| template<typename F > | |
| void | start_duration_timer (const duration &dur, const time_point &when, F &&func) |
| template<typename F > | |
| void | start_timepoint_timer (const duration &dur, F &&func) |
| template<typename F > | |
| void | start_timepoint_timer (const duration &dur, const time_point &when, F &&func) |
| void | cancel () |
|
inlineexplicitnoexcept |
Construct a periodic_timer with an io_context. Other information such as duration will be supplied when start is called.
Constructing a periodic_timer does not start the actual timer. Calling one of the start methods starts the timer.
The application supplied function object for any of the start methods requires the following signature:
The duration parameter provides an elapsed time from the previous callback.
The clock for the asynchronous timer defaults to std::chrono::steady_clock. Other clock types can be used if desired (e.g. std::chrono::high_resolution_clock or std::chrono::system_clock). Note that some clocks allow time to be externally adjusted, which may influence the interval between the callback invocation.
Move semantics are allowed for this type, but not copy semantics. When a move construction or move assignment completes, all timers are cancelled with appropriate notification, and start will need to be called.
| ioc | io_context for asynchronous processing. |
|
inline |
Cancel the timer. The application function object will be called with an "operation aborted" error code.
A cancel may implicitly be called if the periodic_timer object is move copy constructed or move assigned.
|
inline |
Start the timer, and the application supplied function object will be invoked first at a specified time point, then afterwards as specified by the duration parameter.
The function object will continue to be invoked as long as it returns true.
| dur | Interval to be used between callback invocations. |
| when | Time point when the first timer callback will be invoked. |
| func | Function object to be invoked. |
|
inline |
Start the timer, and the application supplied function object will be invoked after an amount of time specified by the duration parameter.
The function object will continue to be invoked as long as it returns true.
| dur | Interval to be used between callback invocations. |
| func | Function object to be invoked. |
|
inline |
Start the timer on the specified timepoint, and the application supplied function object will be invoked on timepoints with an interval specified by the duration.
The function object will continue to be invoked as long as it returns true.
| dur | Interval to be used between callback invocations. |
| when | Time point when the first timer callback will be invoked. |
| func | Function object to be invoked. |
|
inline |
Start the timer, and the application supplied function object will be invoked on timepoints with an interval specified by the duration.
The function object will continue to be invoked as long as it returns true.
| dur | Interval to be used between callback invocations. |
| func | Function object to be invoked. |