If the associated state contains a deferred function from a call to
std::async
then invoke that function and return the result. Otherwise, wait until
the asynchronous result associated with an instance of std::shared_future is ready, and
then return the stored value or throw the stored exception.
void shared_future<void>::get() const; R& shared_future<R&>::get() const; R const& shared_future<R>::get() const;
- Preconditions:
this->valid()would returntrue.- Effects:
-
Calls to
get()andwait()from multiple threads onstd::shared_futureinstances that share the same associated state are serialized. If the associated state contains a deferred function then the first call toget()orwait()invokes the deferred function and stores the returned value or thrown exception as the asynchronous result.Block until the asynchronous result associated with
*thisis ready. If the asynchronous result is a stored exception then throw that exception. Otherwise return the stored value. - Returns:
If
ResultTypeisvoidthen return normally. IfResultTypeisR&for some typeRthen return the stored reference. Otherwise, return aconstreference to the stored value.- Throws:
The stored exception, if any.
Header
#include <future>