99 using duration =
typename Clock::duration;
100 using time_point =
typename Clock::time_point;
104 asio::basic_waitable_timer<Clock> m_timer;
107 template <
typename F>
108 void duration_handler_impl(
const time_point& last_tp,
const duration& dur,
109 const std::error_code& err, F&& func) {
110 time_point now_time { Clock::now() };
112 if (!func(err, now_time - last_tp) ||
113 err == asio::error::operation_aborted) {
116 m_timer.expires_after(dur);
117 m_timer.async_wait( [now_time, dur, f = std::move(func),
this]
118 (
const std::error_code& e) {
119 duration_handler_impl(now_time, dur, e, std::move(f));
123 template <
typename F>
124 void timepoint_handler_impl(
const time_point& last_tp,
const duration& dur,
125 const std::error_code& err, F&& func) {
127 if (!func(err, (Clock::now() - last_tp)) ||
128 err == asio::error::operation_aborted) {
131 m_timer.expires_at(last_tp + dur + dur);
132 m_timer.async_wait( [f = std::move(func), last_tp, dur,
this]
133 (
const std::error_code& e) {
134 timepoint_handler_impl(last_tp+dur, dur, e, std::move(f));
180 m_timer = std::move(rhs.m_timer);
196 template <
typename F>
198 m_timer.expires_after(dur);
199 m_timer.async_wait( [dur, f = std::move(func),
this] (
const std::error_code& e) {
200 duration_handler_impl(Clock::now(), dur, e, std::move(f));
218 template <
typename F>
220 m_timer.expires_at(when);
221 m_timer.async_wait( [dur, f = std::move(func),
this] (
const std::error_code& e) {
222 duration_handler_impl(Clock::now(), dur, e, std::move(f));
237 template <
typename F>
256 template <
typename F>
258 m_timer.expires_at(when);
259 m_timer.async_wait( [when, dur, f = std::move(func),
this]
260 (
const std::error_code& e) {
261 timepoint_handler_impl((when-dur), dur, e, std::move(f));