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_;
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)
233 : state_(std::move(state))
236 state_->OnFutureCreated();
240void Future<T>::CheckValid()
const {
242 throw std::future_error(std::future_errc::no_state);
248 : state_(std::make_shared<impl::FutureState<T>>())
252Promise<T>& Promise<T>::operator=(Promise<T>&& other)
noexcept {
253 if (
this == &other) {
257 [[maybe_unused]]
const auto for_destruction = std::move(*
this);
259 state_ = std::move(other.state_);
264Promise<T>::~Promise() {
265 if (state_ && !state_->IsReady() && state_->IsFutureCreated()) {
267 state_->SetException(std::make_exception_ptr(std::future_error(std::future_errc::broken_promise)));
268 }
catch (
const std::future_error&) {
276 return Future<T>(state_);
281 state_->SetValue(value);
286 state_->SetValue(std::move(value));
291 state_->SetException(std::move(ex));