Utility class wrapping a single non-null callback called by a Timer.
You can use the usual Timer functions to start and stop the TimedCallback. Deleting the TimedCallback will automatically stop the underlying Timer.
With this class you can use the Timer facility without inheritance.
Public Member Functions | |
| TimedCallback (std::function< void()> callbackIn) | |
| Constructor. | |
| ~TimedCallback () noexcept override | |
| Destructor. | |
| void | startTimer (int intervalInMilliseconds) noexcept |
| Starts the timer and sets the length of interval required. | |
| void | startTimerHz (int timerFrequencyHz) noexcept |
| Starts the timer with an interval specified in Hertz. | |
| void | stopTimer () noexcept |
| Stops the timer. | |
| bool | isTimerRunning () const noexcept |
| Returns true if the timer is currently running. | |
| int | getTimerInterval () const noexcept |
| Returns the timer's interval. | |
|
inlineexplicit |
|
inlineoverridenoexcept |
Destructor.
References stopTimer().
|
noexcept |
Starts the timer and sets the length of interval required.
If the timer is already started, this will reset it, so the time between calling this method and the next timer callback will not be less than the interval length passed in.
This method may be called from any thread. It only affects when future callbacks are scheduled. Callbacks themselves always run on the message thread.
| intervalInMilliseconds | the interval to use (any value less than 1 will be rounded up to 1) |
|
noexcept |
Starts the timer with an interval specified in Hertz.
This is effectively the same as calling startTimer (1000 / timerFrequencyHz).
|
noexcept |
Stops the timer.
This method may be called from any thread. It cancels any future callbacks for this timer. If a callback is already running on the message thread, this method does not wait for it to finish and may return while that callback is still executing.
Do not destroy the Timer (or data it uses) from another thread while a callback may still be running. Before destroying a timer it's best practice to stop the timer from the message thread. If the Timer will be destroyed from a background thread consider using MessageManager::callSync() to call stopTimer() from the message thread.
Referenced by ~TimedCallback().
|
inlinenoexcept |
Returns true if the timer is currently running.
|
inlinenoexcept |
Returns the timer's interval.