Timeout
Timeout
#include <icy/timeout.h>Subclassed by:
TimedToken
Timeout counter which expires after a given delay. Delay is specified in milliseconds.
Public Methods
| Return | Name | Description |
|---|---|---|
Timeout | Constructs a Timeout with the given delay. | |
Timeout | Copy constructor. | |
Timeout | Defaulted constructor. | |
bool | running const | Returns true if the timer is currently running. |
void | start | Starts (or restarts) the timer, recording the current time as the start point. |
void | stop | Stops the timer without resetting it. expired() will return false after this call. |
void | reset | Restarts the timer from now, equivalent to calling start(). |
long | remaining const | Returns the number of milliseconds remaining before expiry. Returns 0 if already expired, or the full delay if not running. |
bool | expired const | Returns true if the timer is running and the delay has fully elapsed. |
void | setDelay inline | Sets the expiry delay without restarting the timer. |
long | delay const inline | Returns the configured delay in milliseconds. |
Timeout & | operator= | Copy assignment operator. |
Timeout
Timeout(long delay, bool autoStart)Constructs a Timeout with the given delay.
Parameters
delayExpiry duration in milliseconds (default: 0).autoStartIf true, starts the timer immediately on construction.
Timeout
Timeout(const Timeout & src)Copy constructor.
Parameters
srcSource Timeout to copy state from.
Timeout
Timeout(Timeout && src) = defaultDefaulted constructor.
running
const
bool running() constReturns true if the timer is currently running.
Returns
true if start() has been called and stop() has not.
start
void start()Starts (or restarts) the timer, recording the current time as the start point.
stop
void stop()Stops the timer without resetting it. expired() will return false after this call.
reset
void reset()Restarts the timer from now, equivalent to calling start().
remaining
const
long remaining() constReturns the number of milliseconds remaining before expiry. Returns 0 if already expired, or the full delay if not running.
Returns
Milliseconds until expiry.
expired
const
bool expired() constReturns true if the timer is running and the delay has fully elapsed.
Returns
true if expired, false if stopped or not yet elapsed.
setDelay
inline
inline void setDelay(long delay)Sets the expiry delay without restarting the timer.
Parameters
delayNew delay in milliseconds.
delay
const inline
inline long delay() constReturns the configured delay in milliseconds.
Returns
Delay in milliseconds.
operator=
Timeout & operator=(const Timeout & src)Copy assignment operator.
Parameters
srcSource Timeout to copy state from.
Protected Attributes
_startAt
std::chrono::steady_clock::time_point _startAt_delay
long _delay_running
bool _running