Krzysztof Grobelny | b564594 | 2020-09-29 11:52:45 +0200 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 3 | #include "types/duration_types.hpp" |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 4 | |
Krzysztof Grobelny | b564594 | 2020-09-29 11:52:45 +0200 | [diff] [blame] | 5 | #include <boost/asio/io_context.hpp> |
Krzysztof Grobelny | b564594 | 2020-09-29 11:52:45 +0200 | [diff] [blame] | 6 | #include <boost/asio/steady_timer.hpp> |
| 7 | |
| 8 | #include <chrono> |
| 9 | |
| 10 | namespace utils |
| 11 | { |
| 12 | |
| 13 | template <class F> |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 14 | void makeDetachedTimer(boost::asio::io_context& ioc, Milliseconds delay, |
| 15 | F&& fun) |
Krzysztof Grobelny | b564594 | 2020-09-29 11:52:45 +0200 | [diff] [blame] | 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 |