blob: ae97fabf019d796b233ed1a825338f5734e87ffa [file] [log] [blame]
Krzysztof Grobelnyb5645942020-09-29 11:52:45 +02001#pragma once
2
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +01003#include "types/duration_types.hpp"
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +00004
Krzysztof Grobelnyb5645942020-09-29 11:52:45 +02005#include <boost/asio/io_context.hpp>
Krzysztof Grobelnyb5645942020-09-29 11:52:45 +02006#include <boost/asio/steady_timer.hpp>
7
8#include <chrono>
9
10namespace utils
11{
12
13template <class F>
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000014void makeDetachedTimer(boost::asio::io_context& ioc, Milliseconds delay,
15 F&& fun)
Krzysztof Grobelnyb5645942020-09-29 11:52:45 +020016{
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