Summary
In this chapter, we have seen coroutines, a recently introduced feature in C++ that allows us to write asynchronous code without creating new threads. We have implemented a few simple coroutines to explain the basic requirements of a C++ coroutine. Additionally, we have learned how to implement generators and a string parser. Finally, we have seen exceptions in coroutines.
Coroutines are important in asynchronous programming because they let the program suspend execution at specific points and resume later, allowing other tasks to run in the meantime, all running in the same thread. They allow better resource utilization, reduce waiting time, and improve the scalability of applications.
In the next chapter, we will introduce Boost.Asio – a very powerful library for writing asynchronous code in C++.