15 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_FUTURE_GENERIC_H_ 16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_FUTURE_GENERIC_H_ 23 #include "google/cloud/internal/future_base.h" 24 #include "google/cloud/internal/future_fwd.h" 25 #include "google/cloud/internal/future_impl.h" 26 #include "google/cloud/internal/future_then_meta.h" 35 class future final :
private internal::future_base<T> {
37 using shared_state_type =
38 typename internal::future_base<T>::shared_state_type;
74 std::shared_ptr<shared_state_type> tmp;
75 tmp.swap(
this->shared_state_);
79 using internal::future_base<T>::is_ready;
80 using internal::future_base<T>::valid;
81 using internal::future_base<T>::wait;
82 using internal::future_base<T>::wait_for;
83 using internal::future_base<T>::wait_until;
101 template <
typename F>
104 using requires_unwrap_t =
105 typename internal::then_helper<F, T>::requires_unwrap_t;
106 return then_impl(std::forward<F>(func), requires_unwrap_t{});
109 explicit future(std::shared_ptr<shared_state_type> state)
110 : internal::future_base<T>(std::move(state)) {}
114 template <
typename F>
115 typename internal::then_helper<F, T>::future_t then_impl(F&& functor,
119 template <
typename F>
120 typename internal::then_helper<F, T>::future_t then_impl(F&& functor,
123 template <
typename U>
131 template <
typename T>
132 class promise final :
private internal::promise_base<T> {
138 promise(promise&& rhs)
noexcept =
default;
143 promise tmp(std::move(rhs));
157 promise(promise
const&) =
delete;
158 promise&
operator=(promise
const&) =
delete;
161 void swap(promise& other)
noexcept {
162 std::swap(
this->shared_state_, other.shared_state_);
169 internal::future_shared_state<T>::mark_retrieved(
this->shared_state_);
170 return future<T>(
this->shared_state_);
182 if (!
this->shared_state_) {
183 internal::ThrowFutureError(std::future_errc::no_state,
__func__);
185 this->shared_state_->set_value(std::forward<T>(value));
198 using internal::promise_base<T>::set_exception;
future< T > get_future()
Creates the future<T> using the same shared state as *this.
#define GOOGLE_CLOUD_CPP_NS
future(std::shared_ptr< shared_state_type > state)
Contains all the Google Cloud C++ Library APIs.
promise()=default
Creates a promise with an unsatisfied shared state.
promise & operator=(promise const &)=delete
void swap(promise &other) noexcept
Swaps the shared state in *this with rhs.
promise(promise const &)=delete
T get()
Waits until the shared state becomes ready, then retrieves the value stored in the shared state...
~promise()=default
Abandons any shared state.
future(future< future< T >> &&rhs) noexcept(false)
Creates a new future that unwraps rhs.
void set_value(T const &value)
Satisfies the shared state.
promise & operator=(promise &&rhs) noexcept
Abandons the shared state in *this, if any, and transfers the shared state from rhs.
promise(promise &&rhs) noexcept=default
Constructs a new promise and transfer any shared state from rhs.
void set_value(T &&value)
Satisfies the shared state.
internal::then_helper< F, T >::future_t then(F &&func)
Attach a continuation to the future.