promise
promise
is a type that can be used to set a value that can be awaited via a future
.
The stored data is only destroyed when the promise, and all associated futures go out
of scope. A promise is movable and non-copyable.
Prototype
template <typename T, typename Allocator>
struct promise {
future<T, Allocator> get_future(); // (1)
template <typename U>
void set_value(U &&v); // (2)
void set_value(); // (3)
};
- Obtains the future associated with this promise. This can be called multiple times to get multiple futures.
- Emplaces a value into the promise (overload for
T
other thanvoid
). - Same as (2), except
T
must bevoid
.
Requirements
T
is any type. Allocator
is an allocator. T
is constructible from U
.
Arguments
v
- the value to emplace.
Return values
- This method returns a future object associated with the promise.
- This method doesn't return any value.
- Same as (2).