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