Summary
In this chapter, we learned about promises and futures, how to use them to execute asynchronous code in separate threads, and also how to run callables using packaged tasks. These objects and mechanisms constitute and implement the key concepts of asynchronous programming used by many programming languages, including C++.
We also now understand why promises, futures, and packaged tasks cannot be copied, and thus how to share futures by using shared future objects.
Finally, we have shown how to use futures, promises, and packaged tasks to tackle real-life problems.
If you want to explore promises and futures deeper, it is worth mentioning some third-party open source libraries, especially Boost.Thread and Facebook Folly. These libraries include additional functionality, including callbacks, executors, and combinators.
In the next chapter, we will learn a simpler way to asynchronously invoke callables by using std::async
.