15#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_FUTURE_VOID_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_FUTURE_VOID_H
18
19
20
21
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"
27#include "google/cloud/version.h"
33
34
36class future<
void>
final :
private internal::future_base<
void> {
38 using shared_state_type =
39 typename internal::future_base<
void>::shared_state_type;
46
47
48
49
50
51
52
53
54
55
56
57
58
59
64
65
66
71
72
73
74
75
76
77
80 std::shared_ptr<shared_state_type> tmp;
81 tmp.swap(shared_state_);
85 using future_base::cancel;
86 using future_base::is_ready;
87 using future_base::valid;
88 using future_base::wait;
89 using future_base::wait_for;
90 using future_base::wait_until;
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108 template <
typename F>
109 typename internal::then_helper<F,
void>::
future_t then(F&& func) {
111 using requires_unwrap_t =
112 typename internal::then_helper<F,
void>::requires_unwrap_t;
113 return then_impl(std::forward<F>(func), requires_unwrap_t{});
116 explicit future(std::shared_ptr<shared_state_type> state)
117 : future_base<
void>(std::move(state)) {}
121 template <
typename F>
122 typename internal::then_helper<F,
void>::future_t then_impl(F&& functor,
126 template <
typename F>
127 typename internal::then_helper<F,
void>::future_t then_impl(F&& functor,
130 template <
typename U>
133 friend struct internal::CoroutineSupport;
137
138
140class promise<
void>
final :
private internal::promise_base<
void> {
143 promise() : promise_base([] {}) {}
146 explicit promise(std::function<
void()> cancellation_callback)
147 : promise_base(std::move(cancellation_callback)) {}
150 explicit promise(null_promise_t x) : promise_base(std::move(x)) {}
157 promise&
operator=(promise&& rhs)
noexcept {
158 promise tmp
(std::move(rhs)
);
164
165
166
167
168
169
172 promise(promise
const&) =
delete;
173 promise&
operator=(promise
const&) =
delete;
176 void swap(promise& other)
noexcept {
177 std::swap(shared_state_, other.shared_state_);
181
182
184 shared_state_type::mark_retrieved(shared_state_);
189
190
191
192
193
194
195
197 if (!shared_state_) {
198 internal::ThrowFutureError(std::future_errc::no_state,
__func__);
200 shared_state_->set_value();
203 using promise_base<
void>::set_exception;
void get()
Waits until the shared state becomes ready, then retrieves the value stored in the shared state.
Definition: future_void.h:78
future() noexcept
Definition: future_void.h:43
future(future< T > &&rhs)
Creates a future from a future whose result type is convertible to this future's result type.
Definition: future_void.h:68
future(std::shared_ptr< shared_state_type > state)
Definition: future_void.h:116
internal::then_helper< F, void >::future_t then(F &&func)
Attach a continuation to the future.
Definition: future_void.h:109
future(future< future< void > > &&rhs) noexcept(false)
Creates a new future that unwraps rhs.
friend class future
Definition: future_generic.h:137
promise & operator=(promise const &)=delete
promise & operator=(promise &&rhs) noexcept
Abandons the shared state in *this, if any, and transfers the shared state from rhs.
Definition: future_void.h:157
promise(null_promise_t x)
Creates a promise without a shared state.
Definition: future_void.h:150
future< void > get_future()
Creates the future<void> using the same shared state as *this.
Definition: future_void.h:183
void swap(promise &other) noexcept
Swaps the shared state in *this with rhs.
Definition: future_void.h:176
void set_value()
Satisfies the shared state.
Definition: future_void.h:196
~promise()=default
Abandons any shared state.
promise(std::function< void()> cancellation_callback)
Creates a promise with an unsatisfied shared state.
Definition: future_void.h:146
promise()
Creates a promise with an unsatisfied shared state.
Definition: future_void.h:143
promise(promise &&)=default
Constructs a new promise and transfer any shared state from rhs.
promise(promise const &)=delete
Contains all the Google Cloud C++ Library APIs.
Definition: async_operation.h:23
future< void > make_ready_future()
Create a future<void> that is immediately ready.
Definition: future_void.h:207
Definition: async_operation.h:22
#define GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
Definition: version.h:45
#define GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
Definition: version.h:43