158 std::shared_ptr<impl::FutureState<T>> state_;
162class Promise<
void>
final {
169 Promise(
const Promise&) =
delete;
170 Promise(Promise&&)
noexcept =
default;
171 Promise& operator=(
const Promise&) =
delete;
172 Promise& operator=(Promise&&)
noexcept;
187 std::shared_ptr<impl::FutureState<
void>> state_;
162class Promise<
void>
final {
…};
191bool Future<T>::
valid()
const noexcept {
191bool Future<T>::
valid()
const noexcept {
…}
198 return state_->IsReady();
204 return std::exchange(state_,
nullptr)->Get();
210 return state_->WaitUntil({});
214template <
typename Rep,
typename Period>
216 return wait_until(Deadline::FromDuration(timeout));
220template <
typename Clock,
typename Duration>
222 return wait_until(Deadline::FromTimePoint(until));
228 return state_->WaitUntil(deadline);
232Future<T>::Future(std::shared_ptr<impl::FutureState<T>> state) : state_(std::move(state)) {
234 state_->OnFutureCreated();
238void Future<T>::CheckValid()
const {
240 throw std::future_error(std::future_errc::no_state);
245Promise<T>::
Promise() : state_(std::make_shared<impl::FutureState<T>>()) {}
248Promise<T>& Promise<T>::operator=(Promise<T>&& other)
noexcept {
249 if (
this == &other)
return *
this;
250 { [[maybe_unused]]
const auto for_destruction = std::move(*
this); }
251 state_ = std::move(other.state_);
256Promise<T>::~Promise() {
257 if (state_ && !state_->IsReady() && state_->IsFutureCreated()) {
259 state_->SetException(std::make_exception_ptr(std::future_error(std::future_errc::broken_promise)));
260 }
catch (
const std::future_error&) {
268 return Future<T>(state_);
273 state_->SetValue(value);
278 state_->SetValue(std::move(value));
283 state_->SetException(std::move(ex));