62 using return_type =
typename std::result_of<F(A...)>::type;
64 std::packaged_task<return_type()> task(std::bind(std::forward<F>(f), std::forward<A>(args)...));
65 std::future<return_type> result = task.get_future();
66 std::thread(std::move(task)).detach();
94 const std::chrono::duration<R, P>& delay,
99 return std::async(std::launch::async, [=]() {
100 std::this_thread::sleep_for(delay);
101 return f(std::forward<A>(args)...);
131 const std::chrono::duration<R, P>& timeout,
136 std::promise<
typename std::result_of<F(A...)>::type> promise;
137 std::future<
typename std::result_of<F(A...)>::type> result = promise.get_future();
139 std::thread([=, &promise]() {
141 f(std::forward<A>(args)...);
143 promise.set_exception(std::current_exception());
149 std::thread([=, &promise]() {
150 std::this_thread::sleep_for(timeout);
151 promise.set_exception(std::make_exception_ptr(std::runtime_error(
"Timeout")));
std::future< typename std::result_of< F(A...)>::type > ldvc_async_execute_with_delay(const std::chrono::duration< R, P > &delay, F &&f, A &&... args)
Executes a function asynchronously with a delay.
std::future< typename std::result_of< F(A...)>::type > ldvc_async_execute_with_timeout(const std::chrono::duration< R, P > &timeout, F &&f, A &&... args)
Executes a function asynchronously with a timeout.