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