159 std::shared_ptr<
impl::FutureState<T>> state_;
163class Promise<
void>
final {
170 Promise(
const Promise&) =
delete;
171 Promise(Promise&&)
noexcept =
default;
172 Promise& operator=(
const Promise&) =
delete;
173 Promise& operator=(Promise&&)
noexcept;
188 std::shared_ptr<
impl::FutureState<
void>> state_;
192bool Future<T>::
valid()
const noexcept {
199 return state_->IsReady();
205 return std::exchange(state_,
nullptr)->Get();
211 return state_->WaitUntil({});
215template <
typename Rep,
typename Period>
217 return wait_until(Deadline::FromDuration(timeout));
221template <
typename Clock,
typename Duration>
223 return wait_until(Deadline::FromTimePoint(until));
229 return state_->WaitUntil(deadline);
233Future<T>::Future(std::shared_ptr<
impl::FutureState<T>> state)
234 : state_(std::move(state))
237 state_->OnFutureCreated();
241void Future<T>::CheckValid()
const {
243 throw std::future_error(std::future_errc::no_state);
249 : state_(std::make_shared<
impl::FutureState<T>>())
253Promise<T>& Promise<T>::operator=(Promise<T>&& other)
noexcept {
254 if (
this == &other) {
258 [[maybe_unused]]
const auto for_destruction = std::move(*
this);
260 state_ = std::move(other.state_);
265Promise<T>::~Promise() {
266 if (state_ && !state_->IsReady() && state_->IsFutureCreated()) {
268 state_->SetException(std::make_exception_ptr(std::future_error(std::future_errc::broken_promise)));
269 }
catch (
const std::future_error&) {
277 return Future<T>(state_);
282 state_->SetValue(value);
287 state_->SetValue(std::move(value));
292 state_->SetException(std::move(ex));