The Future Of Business The Essentials Fourth Edition

A std::future is a handle to a result of work which is [potentially] not, yet, computed. You can imagine it as the receipt you get when you ask for work and the receipt is used to get the result back. For example, you may bring a bike to bike store for repair. You get a receipt to get back your bike. While the work is in progress (the bike being repaired) you can go about other business ...
The Future Of Business The Essentials Fourth Edition 1

The class template std::future provides a mechanism to access the result of asynchronous operations: An asynchronous operation (performed via std::async, std::packaged_task, or std::promise) can provide a std::future object to the creator of that asynchronous operation. The creator of the asynchronous operation can then use a variety of methods to query, wait for, or extract a value from the ...

The Future Of Business The Essentials Fourth Edition 2

You cannot return a non- Future value from an async function (although you can return void). You don't actually want the program to stop and wait for the http.get call to complete because if your internet connection is poor then maybe it takes 10 seconds, and your app would consequently be unresponsive for 10 seconds. By returning a Future, you can return from the function immediately without ...

The Future Of Business The Essentials Fourth Edition 3

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.

The promise is the "push" end of the promise-future communication channel: the operation that stores a value in the shared state synchronizes-with (as defined in std::memory_order) the successful return from any function that is waiting on the shared state (such as std::future::get).

The Future Of Business The Essentials Fourth Edition 5