diff --git a/libs/async/include/psemek/async/future.hpp b/libs/async/include/psemek/async/future.hpp index e3a36fa9..d33d9139 100644 --- a/libs/async/include/psemek/async/future.hpp +++ b/libs/async/include/psemek/async/future.hpp @@ -428,19 +428,21 @@ namespace psemek::async { using R = decltype(f()); packaged_task t(std::forward(f)); + auto fut = t.get_future(); std::lock_guard lock{state_->then_mutex}; state_->then_func = std::move(t); - return t.get_future(); + return fut; } else { using R = decltype(f(*(state_->value))); packaged_task t(std::forward(f)); + auto fut = t.get_future(); std::lock_guard lock{state_->then_mutex}; state_->then_func = std::move(t); - return t.get_future(); + return fut; } }