diff --git a/libs/async/include/psemek/async/future.hpp b/libs/async/include/psemek/async/future.hpp index 119bfb6c..ca1cda75 100644 --- a/libs/async/include/psemek/async/future.hpp +++ b/libs/async/include/psemek/async/future.hpp @@ -40,6 +40,18 @@ namespace psemek::async using type = util::function; }; + template + struct future_result_type + { + using type = T &; + }; + + template <> + struct future_result_type + { + using type = void; + }; + struct cancel_token {}; @@ -139,7 +151,7 @@ namespace psemek::async return has_value_unsafe(); } - T get() + typename detail::future_result_type::type get() { if (!state_) throw empty_future_error{}; @@ -151,7 +163,7 @@ namespace psemek::async if constexpr (std::is_same_v) return; else - return std::move(*(state_->value)); + return *(state_->value); } else std::rethrow_exception(state_->exception);