description | title | ms.date | f1_keywords | ms.assetid | helpviewer_keywords | ms.custom | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: future Class |
future Class |
06/15/2022 |
|
495e82c3-5341-4e37-87dd-b40107fbdfb6 |
|
devdivchpfy22 |
Describes an asynchronous return object.
template <class Ty>
class future;
Each standard asynchronous provider returns an object whose type is an instantiation of this template. A future
object provides the only access to the asynchronous provider that it's associated with. If you need multiple asynchronous return objects that are associated with the same asynchronous provider, copy the future
object to a shared_future
object.
Name | Description |
---|---|
future |
Constructs a future object. |
Name | Description |
---|---|
get |
Retrieves the result that is stored in the associated asynchronous state. |
share |
Converts the object to a shared_future . |
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 |
---|---|
future::operator= |
Transfers the associated asynchronous state from a specified object. |
Header: <future>
Namespace: std
Constructs a future
object.
future() noexcept;
future(future&& Other) noexcept;
Other
A future
object.
The first constructor constructs a future
object that has no associated asynchronous state.
The second constructor constructs a future
object and transfers the associated asynchronous state from Other. Other no longer has an associated asynchronous state.
Retrieves the result that is stored in the associated asynchronous state.
Ty get();
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 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 future<void>
, the method returns void
.
In other specializations, the method moves its return value from the stored value. Therefore, call this method only once.
Transfers an associated asynchronous state from a specified object.
future& operator=(future&& Right) noexcept;
Right
A future
object.
*this
After the transfer, Right no longer has an associated asynchronous state.
Converts the object to a shared_future
object.
shared_future<Ty> share();
shared_future(move(*this))
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 interval 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 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.