3#include "util/Mutex.hpp"
5#include <boost/asio/any_io_executor.hpp>
6#include <boost/asio/steady_timer.hpp>
7#include <boost/asio/thread_pool.hpp>
8#include <boost/system/error_code.hpp>
13namespace cluster::impl {
26 boost::asio::steady_timer timer;
28 std::chrono::steady_clock::duration recoveryTime;
31 boost::asio::any_io_executor
const& executor,
32 std::chrono::steady_clock::duration recoveryTime
34 : timer(executor), recoveryTime(recoveryTime)
39 std::shared_ptr<util::Mutex<Impl>> impl_;
49 boost::asio::thread_pool& ctx,
50 std::chrono::steady_clock::duration recoveryTime
69 template <
typename Callback>
73 auto locked = impl_->lock();
74 locked->isRunning =
true;
75 locked->timer.expires_after(locked->recoveryTime);
76 locked->timer.async_wait([impl = impl_, cb = std::forward<Callback>(callback)](
77 boost::system::error_code ec
79 impl->lock()->isRunning =
false;
FallbackRecoveryTimer(boost::asio::thread_pool &ctx, std::chrono::steady_clock::duration recoveryTime)
Construct a timer bound to the given thread pool.
Definition FallbackRecoveryTimer.cpp:12
void cancel()
Cancel any pending async_wait and clear the running flag.
Definition FallbackRecoveryTimer.cpp:27
void start(Callback &&callback)
Arm the timer and schedule callback for when it fires.
Definition FallbackRecoveryTimer.hpp:71
bool isRunning() const
Returns true if an async_wait is currently pending.
Definition FallbackRecoveryTimer.cpp:21