Fix async::futures: notify cv on value set
This commit is contained in:
parent
9dc95c797c
commit
9d29e3a656
1 changed files with 15 additions and 6 deletions
|
|
@ -238,6 +238,7 @@ namespace psemek::async
|
||||||
if (state_->value || state_->exception) throw satisfied_promise_error{};
|
if (state_->value || state_->exception) throw satisfied_promise_error{};
|
||||||
state_->value = value;
|
state_->value = value;
|
||||||
}
|
}
|
||||||
|
state_->value_cv.notify_all();
|
||||||
if (state_->then_func)
|
if (state_->then_func)
|
||||||
state_->then_func(*state_->value);
|
state_->then_func(*state_->value);
|
||||||
}
|
}
|
||||||
|
|
@ -250,6 +251,7 @@ namespace psemek::async
|
||||||
if (state_->value || state_->exception) throw satisfied_promise_error{};
|
if (state_->value || state_->exception) throw satisfied_promise_error{};
|
||||||
state_->value = std::move(value);
|
state_->value = std::move(value);
|
||||||
}
|
}
|
||||||
|
state_->value_cv.notify_all();
|
||||||
if (state_->then_func)
|
if (state_->then_func)
|
||||||
state_->then_func(*state_->value);
|
state_->then_func(*state_->value);
|
||||||
}
|
}
|
||||||
|
|
@ -257,9 +259,12 @@ namespace psemek::async
|
||||||
void set_exception(std::exception_ptr e)
|
void set_exception(std::exception_ptr e)
|
||||||
{
|
{
|
||||||
if (!state_) throw empty_promise_error{};
|
if (!state_) throw empty_promise_error{};
|
||||||
std::lock_guard lock{state_->value_mutex};
|
{
|
||||||
if (state_->value || state_->exception) throw satisfied_promise_error{};
|
std::lock_guard lock{state_->value_mutex};
|
||||||
state_->exception = std::move(e);
|
if (state_->value || state_->exception) throw satisfied_promise_error{};
|
||||||
|
state_->exception = std::move(e);
|
||||||
|
}
|
||||||
|
state_->value_cv.notify_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
future<T> get_future()
|
future<T> get_future()
|
||||||
|
|
@ -318,6 +323,7 @@ namespace psemek::async
|
||||||
if (state_->value || state_->exception) throw satisfied_promise_error{};
|
if (state_->value || state_->exception) throw satisfied_promise_error{};
|
||||||
state_->value = true;
|
state_->value = true;
|
||||||
}
|
}
|
||||||
|
state_->value_cv.notify_all();
|
||||||
if (state_->then_func)
|
if (state_->then_func)
|
||||||
state_->then_func();
|
state_->then_func();
|
||||||
}
|
}
|
||||||
|
|
@ -325,9 +331,12 @@ namespace psemek::async
|
||||||
void set_exception(std::exception_ptr e)
|
void set_exception(std::exception_ptr e)
|
||||||
{
|
{
|
||||||
if (!state_) throw empty_promise_error{};
|
if (!state_) throw empty_promise_error{};
|
||||||
std::lock_guard lock{state_->value_mutex};
|
{
|
||||||
if (state_->value || state_->exception) throw satisfied_promise_error{};
|
std::lock_guard lock{state_->value_mutex};
|
||||||
state_->exception = std::move(e);
|
if (state_->value || state_->exception) throw satisfied_promise_error{};
|
||||||
|
state_->exception = std::move(e);
|
||||||
|
}
|
||||||
|
state_->value_cv.notify_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
future<void> get_future()
|
future<void> get_future()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue