description | title | ms.date | f1_keywords | ms.assetid | helpviewer_keywords | ms.custom | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: shared_future Class |
shared_future Class |
06/20/2022 |
|
454ebedd-f42b-405f-99a5-a25cc9ad7c90 |
|
devdivchpfy22 |
Describes an asynchronous return object. In contrast with a future object, an asynchronous provider can be associated with any number of shared_future
objects.
template <class Ty>
class shared_future;
Don't call any methods other than valid
, operator=
, and the destructor on a shared_future
object that's empty.
shared_future
objects aren't synchronized. Calling methods on the same object from multiple threads introduces a data race that has unpredictable results.
Name | Description |
---|---|
shared_future | Constructs a shared_future object. |
Name | Description |
---|---|
get | Retrieves the result that's stored in the associated asynchronous state. |
valid | Specifies whether the object isn't empty. |
wait | Blocks the current thread until the associated asynchronous state is ready. |
wait_for | Blocks until the associated asynchronous state is ready or until the specified time has elapsed. |
wait_until | Blocks until the associated asynchronous state is ready or until a specified point in time. |
Name | Description |
---|---|
shared_future::operator= | Assigns a new associated asynchronous state. |
Header: <future>
Namespace: std
Retrieves the result that's stored in the associated asynchronous state.
const Ty& get() const;
Ty& get() const;
void get() const;
If the result is an exception, the method rethrows it. Otherwise, the result is returned.
Before it retrieves the result, this method blocks the current thread until the associated asynchronous state is ready.
For the partial specialization shared_future<Ty&>
, the stored value is effectively a reference to the object that was passed to the asynchronous provider as the return value.
Because no stored value exists for the specialization shared_future<void>
, the method returns void
.
Transfers an associated asynchronous state from a specified object.
shared_future& operator=(shared_future&& Right) noexcept;
shared_future& operator=(const shared_future& Right);
Right
A shared_future
object.
*this
For the first operator, Right no longer has an associated asynchronous state after the operation.
For the second method, Right maintains its associated asynchronous state.
Constructs a shared_future
object.
shared_future() noexcept;
shared_future(future<Ty>&& Right) noexcept;
shared_future(shared_future&& Right) noexcept;
shared_future(const shared_future& Right);
Right
A future or shared_future
object.
The first constructor constructs a shared_future
object that has no associated asynchronous state.
The second and third constructors construct a shared_future
object and transfer the associated asynchronous state from Right. Right no longer has an associated asynchronous state.
The fourth constructor constructs a shared_future
object that has the same associated asynchronous state as Right.
Specifies whether the object has an associated asynchronous state.
bool valid() noexcept;
true
if the object has an associated asynchronous state; otherwise, false
.
Blocks the current thread until the associated asynchronous state is ready.
void wait() const;
An associated asynchronous state is ready only if its asynchronous provider has stored a return value or stored an exception.
Blocks the current thread until the associated asynchronous state is ready or until a specified time has elapsed.
template <class Rep, class Period>
future_status wait_for(
const chrono::duration<Rep, Period>& Rel_time) const;
Rel_time
A chrono::duration object that specifies a maximum time interval that the thread blocks.
A future_status that indicates the reason for returning.
An associated asynchronous state is ready only if its asynchronous provider has stored a return value or stored an exception.
Blocks the current thread until the associated asynchronous state is ready or until after a specified time point.
template <class Clock, class Duration>
future_status wait_until(
const chrono::time_point<Clock, Duration>& Abs_time) const;
Abs_time
A chrono::time_point object that specifies a time after which the thread can unblock.
A future_status that indicates the reason for returning.
An associated asynchronous state is ready only if its asynchronous provider has stored a return value or stored an exception.