Timer
Timer
#include <icy/timer.h>Inherits:
Runner
Asynchronous event based timer.
Public Attributes
Timeout
NullSignal TimeoutSignal that gets triggered on timeout.
Public Methods
| Return | Name | Description |
|---|---|---|
Timer | Create a timer without a timeout or interval; values must be set before [start()](#start-12). | |
Timer | Create a one-shot timer that fires after timeout milliseconds. | |
Timer | Create a repeating timer with an initial delay and a repeat period. | |
~Timer virtual | Destructor. | |
void | start | Start the timer using the previously configured timeout and interval. |
void | start virtual | Connect func to the [Timeout](icy-Timeout.html#timeout-1) signal and start the timer. |
void | stop | Stop the timer. Resets the fire count to zero. |
void | restart | Restart the timer. |
void | again | Reset the countdown without stopping and restarting the timer. |
void | setTimeout | Set the initial delay before the first timeout event. |
void | setInterval | Set the repeat interval (calls uv_timer_set_repeat). |
bool | active const | #### Returns |
std::int64_t | timeout const | #### Returns |
std::int64_t | interval const | #### Returns |
std::int64_t | count | #### Returns |
uv::Handle< uv_timer_t > & | handle | #### Returns |
bool | async virtual const | #### Returns |
Timer
Timer(uv::Loop * loop)Create a timer without a timeout or interval; values must be set before [start()](#start-12).
Parameters
loopEvent loop to associate with. Defaults to the process-wide default loop.
Timer
Timer(std::int64_t timeout, uv::Loop * loop, std::function< void()> func)Create a one-shot timer that fires after timeout milliseconds.
If func is provided the timer starts immediately; otherwise call [start()](#start-12) manually.
Parameters
timeoutDelay in milliseconds before the first (and only) fire.loopEvent loop to associate with.funcOptional callback connected to the[Timeout](icy-Timeout.html#timeout-1)signal and used to start the timer immediately.
Timer
Timer(std::int64_t timeout, std::int64_t interval, uv::Loop * loop, std::function< void()> func)Create a repeating timer with an initial delay and a repeat period.
Fires once after timeout milliseconds, then repeatedly every interval milliseconds. If func is provided the timer starts immediately; otherwise call [start()](#start-12) manually.
Parameters
timeoutInitial delay in milliseconds.intervalRepeat period in milliseconds.loopEvent loop to associate with.funcOptional callback connected to the[Timeout](icy-Timeout.html#timeout-1)signal and used to start the timer immediately.
~Timer
virtual
virtual ~Timer()Destructor.
start
void start()Start the timer using the previously configured timeout and interval.
Throws std::logic_error if neither a timeout nor an interval has been set, or if the handle has not been allocated. Has no effect if already active.
start
virtual
virtual void start(std::function< void()> func)Connect func to the [Timeout](icy-Timeout.html#timeout-1) signal and start the timer.
Parameters
funcCallback invoked on each timeout event.
stop
void stop()Stop the timer. Resets the fire count to zero.
Has no effect if the timer is not active.
restart
void restart()Restart the timer.
If the timer is not currently active, behaves like [start()](#start-12). If it is active, calls [again()](#again) to reset the countdown using the repeat value. A timeout or interval must be set beforehand, otherwise [start()](#start-12) will throw std::logic_error.
again
void again()Reset the countdown without stopping and restarting the timer.
For repeating timers this restarts the repeat interval from now. For non-repeating timers this has the same effect as stopping the timer. Throws on error if uv_timer_again fails (e.g. the timer was never started). Resets the fire count to zero.
setTimeout
void setTimeout(std::int64_t timeout)Set the initial delay before the first timeout event.
Has no effect if the timer is currently active.
Parameters
timeoutDelay in milliseconds.
setInterval
void setInterval(std::int64_t interval)Set the repeat interval (calls uv_timer_set_repeat).
Takes effect from the next timeout event. If set from within a timer callback on a repeating timer, the new value is used from the following iteration; on a non-repeating timer the timer will have already stopped.
Parameters
intervalRepeat period in milliseconds; 0 disables repeating.
active
const
bool active() constReturns
true if the timer is currently counting down.
timeout
const
std::int64_t timeout() constReturns
The configured initial timeout in milliseconds.
interval
const
std::int64_t interval() constReturns
The effective repeat interval reported by libuv, in milliseconds.
count
std::int64_t count()Returns
The number of times the timer has fired since the last start or again().
handle
uv::Handle< uv_timer_t > & handle()Returns
Reference to the underlying uv_timer_t handle wrapper.
async
virtual const
virtual bool async() constReturns
false; the timer is event-loop-driven, not thread-based.
Protected Attributes
| Return | Name | Description |
|---|---|---|
uv::Handle< uv_timer_t > | _handle | |
std::int64_t | _timeout | |
std::int64_t | _interval | |
std::int64_t | _count |
_handle
uv::Handle< uv_timer_t > _handle_timeout
std::int64_t _timeout_interval
std::int64_t _interval_count
std::int64_t _countProtected Methods
Timer
Timer(const Timer &) = deleteDeleted constructor.
Timer
Timer(Timer &&) = deleteDeleted constructor.
init
void init()