4#include <boost/asio/steady_timer.hpp> 
    5#include <boost/asio/strand.hpp> 
    6#include <boost/asio/use_future.hpp> 
   14  template <
typename Executor>
 
   15  explicit timer(boost::asio::strand<Executor>& ctx, boost::asio::io_context& ioctx)
 
   21  explicit timer(boost::asio::io_context& ctx)
 
   22      : m_timer{boost::asio::make_strand(ctx)}
 
   27  timer(
const timer&) = 
delete;
 
   28  timer(timer&& other) noexcept
 
   29      : m_timer{std::move(other.m_timer)}
 
   30      , m_context{other.m_context}
 
   31      , m_delay{other.m_delay}
 
   35  timer& operator=(
const timer&) = 
delete;
 
   36  timer& operator=(timer&& other) 
noexcept 
   38    m_timer = std::move(other.m_timer);
 
   39    m_delay = other.m_delay;
 
   45  void set_delay(std::chrono::milliseconds ms) 
noexcept { m_delay = ms; }
 
   46  void set_delay(std::chrono::microseconds ms) 
noexcept 
   48    m_delay = std::chrono::duration_cast<std::chrono::milliseconds>(ms);
 
   54    m_timer.expires_after(m_delay);
 
   55    m_timer.async_wait([
this, ff = std::move(f)](
auto ec) {
 
   56      if(ec == boost::asio::error::operation_aborted)
 
   66        this->start(std::move(ff));
 
   73    auto exec = m_timer.get_executor();
 
   74    boost::asio::dispatch(
 
   75        exec, [tm = std::make_shared<boost::asio::steady_timer>(
 
   76                   std::move(m_timer))]() 
mutable { tm->cancel(); });
 
   78    if(!m_context.stopped())
 
   80      std::future<void> wait = boost::asio::dispatch(exec, boost::asio::use_future);
 
   81      wait.wait_for(std::chrono::seconds(2));
 
   86  boost::asio::steady_timer m_timer;
 
   87  boost::asio::io_context& m_context;
 
   88  std::chrono::milliseconds m_delay{};
 
spdlog::logger & logger() noexcept
Where the errors will be logged. Default is stderr.
Definition context.cpp:118