Base module

Timeout

[Timeout]({#ref classicy_1_1Timeout #}) counter which expires after a given delay.

Timeout

#include <icy/timeout.h>

Subclassed by: TimedToken

Timeout counter which expires after a given delay. Delay is specified in milliseconds.

Public Methods

ReturnNameDescription
TimeoutConstructs a Timeout with the given delay.
TimeoutCopy constructor.
TimeoutDefaulted constructor.
boolrunning constReturns true if the timer is currently running.
voidstartStarts (or restarts) the timer, recording the current time as the start point.
voidstopStops the timer without resetting it. expired() will return false after this call.
voidresetRestarts the timer from now, equivalent to calling start().
longremaining constReturns the number of milliseconds remaining before expiry. Returns 0 if already expired, or the full delay if not running.
boolexpired constReturns true if the timer is running and the delay has fully elapsed.
voidsetDelay inlineSets the expiry delay without restarting the timer.
longdelay const inlineReturns the configured delay in milliseconds.
Timeout &operator=Copy assignment operator.

Timeout

Timeout(long delay, bool autoStart)

Constructs a Timeout with the given delay.

Parameters

  • delay Expiry duration in milliseconds (default: 0).

  • autoStart If true, starts the timer immediately on construction.


Timeout

Timeout(const Timeout & src)

Copy constructor.

Parameters

  • src Source Timeout to copy state from.

Timeout

Timeout(Timeout && src) = default

Defaulted constructor.


running

const

bool running() const

Returns 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() const

Returns 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() const

Returns 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

  • delay New delay in milliseconds.

delay

const inline

inline long delay() const

Returns the configured delay in milliseconds.

Returns

Delay in milliseconds.


operator=

Timeout & operator=(const Timeout & src)

Copy assignment operator.

Parameters

  • src Source Timeout to copy state from.

Protected Attributes

ReturnNameDescription
std::chrono::steady_clock::time_point_startAt
long_delay
bool_running

_startAt

std::chrono::steady_clock::time_point _startAt

_delay

long _delay

_running

bool _running