blob: 224e5a10a36e5bb49cf9b5cd50aba497fa4f2653 [file] [log] [blame]
Krzysztof Grobelnyb5645942020-09-29 11:52:45 +02001#pragma once
2
3#include <boost/asio/io_context.hpp>
Krzysztof Grobelnyb5645942020-09-29 11:52:45 +02004#include <boost/asio/steady_timer.hpp>
5
6#include <chrono>
7
8namespace utils
9{
10
11template <class F>
12void 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