RAVENNAKIT
Loading...
Searching...
No Matches
rav::AsioTimer Class Reference

A timer that uses boost::asio::steady_timer to provide a simple way of creating a timer without thinking about the lifetimes. More...

#include <asio_timer.hpp>

Public Types

using TimerCallback = std::function<void()>

Public Member Functions

 AsioTimer (boost::asio::io_context &io_context)
 ~AsioTimer ()
void once (std::chrono::milliseconds duration, TimerCallback cb)
 Fires the callback once after the given duration.
void start (std::chrono::milliseconds duration, TimerCallback cb, bool repeating=true)
 Fires the callback after the given duration.
void stop ()
 Stops the timer and cancels any pending callbacks.

Detailed Description

A timer that uses boost::asio::steady_timer to provide a simple way of creating a timer without thinking about the lifetimes.

Definition at line 37 of file asio_timer.hpp.

Member Typedef Documentation

◆ TimerCallback

using rav::AsioTimer::TimerCallback = std::function<void()>

Definition at line 39 of file asio_timer.hpp.

Constructor & Destructor Documentation

◆ AsioTimer()

rav::AsioTimer::AsioTimer ( boost::asio::io_context & io_context)
explicit

◆ ~AsioTimer()

rav::AsioTimer::~AsioTimer ( )

Member Function Documentation

◆ once()

void rav::AsioTimer::once ( std::chrono::milliseconds duration,
TimerCallback cb )

Fires the callback once after the given duration.

The timer will be stopped before starting a new one.

Parameters
durationThe duration to wait before firing the callback.
cbThe callback to fire after the duration.

◆ start()

void rav::AsioTimer::start ( std::chrono::milliseconds duration,
TimerCallback cb,
bool repeating = true )

Fires the callback after the given duration.

The callback will be fired repeatedly until stopped. The timer will be stopped before starting a new one. Safe to call from any thread.

Parameters
durationThe duration to wait before firing the callback.
cbThe callback to fire after the duration.
repeatingIf true, the timer will repeat the callback after each duration.

◆ stop()

void rav::AsioTimer::stop ( )

Stops the timer and cancels any pending callbacks.

After this call returns, no more callbacks will be fired. Can be called from any thread. The work is scheduled on the io_context thread.


The documentation for this class was generated from the following file: