Commit cf108c38 authored by Max Kellermann's avatar Max Kellermann

win32/ComWorker: remove parameter passing from Async()

Parameters should better be captured. This removes some complexity from Async().
parent 90d97053
...@@ -65,24 +65,19 @@ public: ...@@ -65,24 +65,19 @@ public:
COMWorker(const COMWorker &) = delete; COMWorker(const COMWorker &) = delete;
COMWorker &operator=(const COMWorker &) = delete; COMWorker &operator=(const COMWorker &) = delete;
template <typename Function, typename... Args> template<typename Function>
auto Async(Function &&function, Args &&...args) { auto Async(Function &&function) {
using R = std::invoke_result_t<std::decay_t<Function>, using R = std::invoke_result_t<std::decay_t<Function>>;
std::decay_t<Args>...>;
auto promise = std::make_shared<Promise<R>>(); auto promise = std::make_shared<Promise<R>>();
auto future = promise->get_future(); auto future = promise->get_future();
thread.Push([function = std::forward<Function>(function), thread.Push([function = std::forward<Function>(function),
args = std::make_tuple(std::forward<Args>(args)...),
promise = std::move(promise)]() mutable { promise = std::move(promise)]() mutable {
try { try {
if constexpr (std::is_void_v<R>) { if constexpr (std::is_void_v<R>) {
std::apply(std::forward<Function>(function), std::invoke(std::forward<Function>(function));
std::move(args));
promise->set_value(); promise->set_value();
} else { } else {
promise->set_value(std::apply( promise->set_value(std::invoke(std::forward<Function>(function)));
std::forward<Function>(function),
std::move(args)));
} }
} catch (...) { } catch (...) {
promise->set_exception(std::current_exception()); promise->set_exception(std::current_exception());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment