Timer
Timer
#include <icy/timer.h>class TimerDefined in src/base/include/icy/timer.h:27
Inherits:
Runner
Asynchronous event based timer.
List of all members
| Name | Kind | Owner |
|---|---|---|
Timeout | variable | Declared here |
Timer | function | Declared here |
Timer | function | Declared here |
Timer | function | Declared here |
~Timer | function | Declared here |
start | function | Declared here |
start | function | Declared here |
stop | function | Declared here |
restart | function | Declared here |
again | function | Declared here |
setTimeout | function | Declared here |
setInterval | function | Declared here |
active | function | Declared here |
timeout | function | Declared here |
interval | function | Declared here |
count | function | Declared here |
handle | function | Declared here |
async | function | Declared here |
_handle | variable | Declared here |
_timeout | variable | Declared here |
_interval | variable | Declared here |
_count | variable | Declared here |
Timer | function | Declared here |
operator= | function | Declared here |
Timer | function | Declared here |
operator= | function | Declared here |
init | function | Declared here |
Runner | function | Inherited from Runner |
~Runner | function | Inherited from Runner |
start | function | Inherited from Runner |
running | function | Inherited from Runner |
cancel | function | Inherited from Runner |
cancelled | function | Inherited from Runner |
repeating | function | Inherited from Runner |
setRepeating | function | Inherited from Runner |
async | function | Inherited from Runner |
tid | function | Inherited from Runner |
waitForExit | function | Inherited from Runner |
_context | variable | Inherited from Runner |
Runner | function | Inherited from Runner |
operator= | function | Inherited from Runner |
Runner | function | Inherited from Runner |
operator= | function | Inherited from Runner |
Inherited from Runner
| Kind | Name | Description |
|---|---|---|
function | Runner | |
function | ~Runner virtual | |
function | start virtual | Starts the asynchronous context with the given callback. The callback must remain valid for the lifetime of the [Runner](icy-Runner.html#runner). |
function | running const | Returns true if the async context is currently running. |
function | cancel | Signals the async context to stop at the earliest opportunity. |
function | cancelled const | Returns true if the context has been cancelled. The implementation is responsible for exiting as soon as possible after cancellation. |
function | repeating const | Returns true if the runner is in repeating mode. |
function | setRepeating | Enables or disables repeating mode. When repeating, the target function is invoked repeatedly until [cancel()](icy-Runner.html#cancel-2) is called. This normalizes behaviour across thread-based and event-loop-based [Runner](icy-Runner.html#runner) implementations. Must be called before [start()](icy-Runner.html#start-3). |
function | async virtual const | Returns true if the implementation is thread-based. |
function | tid const | Returns the native thread ID of the thread running the async context. |
function | waitForExit | Blocks until the async context exits or the timeout elapses. The context should be cancelled before calling this method. Must be called from outside the runner's own thread to avoid deadlock. |
variable | _context | Shared pointer to the internal Context. |
function | Runner | NonCopyable and NonMovable. |
function | operator= | Deleted assignment operator. |
function | Runner | Deleted constructor. |
function | operator= | Deleted assignment operator. |
Public Attributes
Timeout
NullSignal TimeoutDefined in src/base/include/icy/timer.h:130
Signal 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 override | 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 | |
std::int64_t | timeout const | |
std::int64_t | interval const | |
std::int64_t | count | |
uv::Handle< uv_timer_t > & | handle | |
bool | async virtual const override |
Timer
Timer(uv::Loop * loop = uv::defaultLoop())Defined in src/base/include/icy/timer.h:33
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 = uv::defaultLoop(), std::function< void()> func = nullptr)Defined in src/base/include/icy/timer.h:44
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 = uv::defaultLoop(), std::function< void()> func = nullptr)Defined in src/base/include/icy/timer.h:57
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()Defined in src/base/include/icy/timer.h:60
Destructor.
start
void start()Defined in src/base/include/icy/timer.h:67
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 override
virtual void start(std::function< void()> func) overrideDefined in src/base/include/icy/timer.h:72
Connect func to the [Timeout](icy-Timeout.html#timeout-1) signal and start the timer.
Parameters
funcCallback invoked on each timeout event.
Reimplements
stop
void stop()Defined in src/base/include/icy/timer.h:77
Stop the timer. Resets the fire count to zero.
Has no effect if the timer is not active.
restart
void restart()Defined in src/base/include/icy/timer.h:85
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()Defined in src/base/include/icy/timer.h:93
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)Defined in src/base/include/icy/timer.h:100
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)Defined in src/base/include/icy/timer.h:109
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() constDefined in src/base/include/icy/timer.h:112
Returns
true if the timer is currently counting down.
timeout
const
std::int64_t timeout() constDefined in src/base/include/icy/timer.h:115
Returns
The configured initial timeout in milliseconds.
interval
const
std::int64_t interval() constDefined in src/base/include/icy/timer.h:118
Returns
The effective repeat interval reported by libuv, in milliseconds.
count
std::int64_t count()Defined in src/base/include/icy/timer.h:121
Returns
The number of times the timer has fired since the last start or again().
handle
uv::Handle< uv_timer_t > & handle()Defined in src/base/include/icy/timer.h:124
Returns
Reference to the underlying uv_timer_t handle wrapper.
async
virtual const override
virtual bool async() const overrideDefined in src/base/include/icy/timer.h:127
Returns
false; the timer is event-loop-driven, not thread-based.
Reimplements
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 > _handleDefined in src/base/include/icy/timer.h:140
_timeout
std::int64_t _timeoutDefined in src/base/include/icy/timer.h:141
_interval
std::int64_t _intervalDefined in src/base/include/icy/timer.h:142
_count
std::int64_t _countDefined in src/base/include/icy/timer.h:143
Protected Methods
Timer
Timer(const Timer &) = deleteDefined in src/base/include/icy/timer.h:133
Deleted constructor.
Timer
Timer(Timer &&) = deleteDefined in src/base/include/icy/timer.h:135
Deleted constructor.
init
void init()