1 #pragma once 2 3 #include "types/duration_types.hpp" 4 5 #include <boost/asio/io_context.hpp> 6 #include <boost/asio/steady_timer.hpp> 7 8 #include <chrono> 9 10 namespace utils 11 { 12 13 template <class F> 14 void makeDetachedTimer(boost::asio::io_context& ioc, Milliseconds delay, 15 F&& fun) 16 { 17 auto timer = std::make_unique<boost::asio::steady_timer>(ioc); 18 timer->expires_after(delay); 19 timer->async_wait([timer = std::move(timer), 20 fun = std::move(fun)](boost::system::error_code ec) { 21 if (ec) 22 { 23 return; 24 } 25 fun(); 26 }); 27 } 28 29 } // namespace utils 30