Class Timer

Page Contents

Class Documentation

class Timer

The Timer class provides an interface for queuing tasks for execution after a given delay. More than one timer or interval can be scheduled at a time, however calling Clear() on the timer instance will stop all scheduled timers simultaneously.

Public Functions

Timer(pplx::cancellation_token cts, std::shared_ptr<logging::BaseLogger> logger)
inline ~Timer()
void Clear()

Clears the active timer, halting any current operation.

pplx::task<void> SetInterval(std::function<void()> func, uint64_t interval)

Sets an interval timer and begins execution for the given time interval. Calls the given function on every elapsed interval.

Parameters
  • func – The function to call at every interval.

  • interval – The time, in milliseconds, of the interval.

Returns

The task that will be executed upon each occurrence of the timer interval.

pplx::task<void> SetTimeout(std::function<void()> func, uint64_t timeout)

Sets a timer to execute a given function after the specified amount of time has elapsed.

Parameters
  • func – The function to call once the set time as elapsed.

  • interval – The time, in milliseconds, to wait before the task will be executed.

Returns

The task that will be executed after the timer completes.