4 #include <boost/asio/steady_timer.hpp>
5 #include <boost/asio/strand.hpp>
6 #include <boost/asio/use_future.hpp>
14 explicit timer(boost::asio::io_context& ctx)
16 , m_timer{boost::asio::make_strand(ctx)}
20 timer(
const timer&) =
delete;
21 timer(timer&&) =
default;
22 timer& operator=(
const timer&) =
delete;
23 timer& operator=(timer&&) =
default;
27 void set_delay(std::chrono::milliseconds ms) noexcept { m_delay = ms; }
32 m_timer.expires_from_now(m_delay);
33 m_timer.async_wait([
this, ff = std::move(f)](
auto ec) {
34 if(ec == boost::asio::error::operation_aborted)
44 this->start(std::move(ff));
51 boost::asio::dispatch(
52 m_timer.get_executor(), [tm = std::make_shared<boost::asio::steady_timer>(
53 std::move(m_timer))]()
mutable { tm->cancel(); });
54 std::future<void> wait
55 = boost::asio::dispatch(m_timer.get_executor(), boost::asio::use_future);
60 boost::asio::io_context* m_ctx{};
61 boost::asio::steady_timer m_timer;
62 std::chrono::milliseconds m_delay{};
spdlog::logger & logger() noexcept
Where the errors will be logged. Default is stderr.
Definition: context.cpp:104