Future<String> someLongComputation() async { ... } above, someLongComputation will immediately return a future, and after some time, said future will resolve with a string. What the await keyword does is wait until the future has returned a value and then returns said value, basically turning an asynchronous computation into a synchronous one, of course this would negate the whole point of ...

Understanding the Context

The class template std::promise provides a facility to store a value or an exception that is later acquired asynchronously via a std::future object created by the std::promise object. Note that the std::promise object is meant to be used only once. Each promise is associated with a shared state, which contains some state information and a result which may be not yet evaluated, evaluated to a ... C++ includes built-in support for threads, atomic operations, mutual exclusion, condition variables, and futures.

Key Insights

wait_until waits for a result to become available. It blocks until specified timeout_time has been reached or the result becomes available, whichever comes first. The return value indicates why wait_until returned. If the future is the result of a call to async that used lazy evaluation, this function returns immediately without waiting. The behavior is undefined if valid () is false before ...

Final Thoughts

future (const future &) = delete; ~future (); future & operator =(const future &) = delete; future & operator =(future &&) noexcept; shared_future <R> share () noexcept; // retrieving the value /* see description */ get (); // functions to check state bool valid () const noexcept; void wait () const; template<class Rep, class Period> The class template std::packaged_task wraps any Callable target (function, lambda expression, bind expression, or another function object) so that it can be invoked asynchronously. Its return value or exception thrown is stored in a shared state which can be accessed through std::future objects. If the future is the result of a call to std::async that used lazy evaluation, this function returns immediately without waiting. This function may block for longer than timeout_duration due to scheduling or resource contention delays. The standard recommends that a steady clock is used to measure the duration.