OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
ossia::timer Class Reference

Calls a function periodically on a strand. More...

Detailed Description

Calls a function periodically on a strand.

Once stop() returns, the function is not called any more: stop() raises a flag the handler checks before calling the function and before re-arming, cancels the wait on the strand, and, while the context runs, waits until the strand is past a call in progress. The cancel has to run on the strand: a handler running there re-arms the asio timer, and a cancel from another thread would race with it and miss the new wait. The asio timer and the flag live in a state the handlers share, so a handler that runs late, or after the ossia::timer moved, never reaches freed memory.

Public Member Functions

template<typename Executor>
 timer (boost::asio::strand< Executor > &ctx, boost::asio::io_context &ioctx)
 timer (boost::asio::io_context &ctx)
 timer (const timer &)=delete
 timer (timer &&other) noexcept
timer & operator= (const timer &)=delete
timer & operator= (timer &&other) noexcept
void set_delay (std::chrono::milliseconds ms) noexcept
 Applies from the next wait on when the timer runs.
void set_delay (std::chrono::microseconds ms) noexcept
template<typename F>
void start (F f)
void stop ()