12
Coroutines and Lazy Generators
Computing has become a world of waiting, and we need support in our programming languages to be able to express wait. The general idea is to suspend (temporarily pause) the current flow and hand execution over to some other flow, whenever it reaches a point where we know that we might have to wait for something. This something that we need to wait for could be a network request, a click from a user, a database operation, or even a memory access that is taking too long for us to block at. Instead, we say in our code that we will wait, continue some other flow, and then come back when ready. Coroutines allow us to do that.
In this chapter, we're mainly going to focus on coroutines added to C++20. You will learn ...
Get C++ High Performance - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.