dxFeed Graal CXX API v9.0.0
Loading...
Searching...
No Matches
Timer Struct Referencefinal

A simple thread-safe timer. More...

#include <Timer.hpp>

Public Member Functions

void interruptableSleep (std::chrono::milliseconds ms) const
 Sleeps for the specified time or until the timer is stopped.
void interruptableSleep (std::uint64_t ms) const
 Sleeps for the specified number of milliseconds or until the timer is stopped.
void stop ()
 Stops the timer: the function is not run any more and the sleeping thread wakes up.
bool isRunning ()

Static Public Member Functions

template<typename F, typename Delay, typename Period>
static std::shared_ptr< Timer > schedule (F &&f, Delay &&delay, Period &&period)
 Runs the function on a separate thread after the delay and then with the period until the timer is stopped or the function throws.
template<typename F, typename Delay>
static std::shared_ptr< Timer > runOnce (F &&f, Delay &&delay)
 Runs the function once on a separate thread after the delay, unless the timer is stopped before.

Detailed Description

A simple thread-safe timer.

Member Function Documentation

◆ interruptableSleep() [1/2]

void Timer::interruptableSleep ( std::chrono::milliseconds ms) const

Sleeps for the specified time or until the timer is stopped.

Parameters
msThe time to sleep.

◆ interruptableSleep() [2/2]

void Timer::interruptableSleep ( std::uint64_t ms) const

Sleeps for the specified number of milliseconds or until the timer is stopped.

Parameters
msThe number of milliseconds to sleep.

◆ isRunning()

bool Timer::isRunning ( )
Returns
true if the timer has not been stopped and its function may still run.

◆ runOnce()

template<typename F, typename Delay>
std::shared_ptr< Timer > Timer::runOnce ( F && f,
Delay && delay )
inlinestatic

Runs the function once on a separate thread after the delay, unless the timer is stopped before.

Template Parameters
FThe type of the function.
DelayThe type of the delay: a std::chrono::duration or a number of milliseconds.
Parameters
fThe function.
delayThe delay before the run.
Returns
The running timer.

◆ schedule()

template<typename F, typename Delay, typename Period>
std::shared_ptr< Timer > Timer::schedule ( F && f,
Delay && delay,
Period && period )
inlinestatic

Runs the function on a separate thread after the delay and then with the period until the timer is stopped or the function throws.

Template Parameters
FThe type of the function.
DelayThe type of the delay: a std::chrono::duration or a number of milliseconds.
PeriodThe type of the period: a std::chrono::duration or a number of milliseconds.
Parameters
fThe function.
delayThe delay before the first run.
periodThe period between the runs.
Returns
The running timer.