diff --git a/libs/async/include/psemek/async/future.hpp b/libs/async/include/psemek/async/future.hpp index f66702a7..dd545f0d 100644 --- a/libs/async/include/psemek/async/future.hpp +++ b/libs/async/include/psemek/async/future.hpp @@ -238,6 +238,7 @@ namespace psemek::async if (state_->value || state_->exception) throw satisfied_promise_error{}; state_->value = value; } + state_->value_cv.notify_all(); if (state_->then_func) state_->then_func(*state_->value); } @@ -250,6 +251,7 @@ namespace psemek::async if (state_->value || state_->exception) throw satisfied_promise_error{}; state_->value = std::move(value); } + state_->value_cv.notify_all(); if (state_->then_func) state_->then_func(*state_->value); } @@ -257,9 +259,12 @@ namespace psemek::async void set_exception(std::exception_ptr e) { if (!state_) throw empty_promise_error{}; - std::lock_guard lock{state_->value_mutex}; - if (state_->value || state_->exception) throw satisfied_promise_error{}; - state_->exception = std::move(e); + { + std::lock_guard lock{state_->value_mutex}; + if (state_->value || state_->exception) throw satisfied_promise_error{}; + state_->exception = std::move(e); + } + state_->value_cv.notify_all(); } future get_future() @@ -318,6 +323,7 @@ namespace psemek::async if (state_->value || state_->exception) throw satisfied_promise_error{}; state_->value = true; } + state_->value_cv.notify_all(); if (state_->then_func) state_->then_func(); } @@ -325,9 +331,12 @@ namespace psemek::async void set_exception(std::exception_ptr e) { if (!state_) throw empty_promise_error{}; - std::lock_guard lock{state_->value_mutex}; - if (state_->value || state_->exception) throw satisfied_promise_error{}; - state_->exception = std::move(e); + { + std::lock_guard lock{state_->value_mutex}; + if (state_->value || state_->exception) throw satisfied_promise_error{}; + state_->exception = std::move(e); + } + state_->value_cv.notify_all(); } future get_future()