
C++ High Performance
By :

We already talked a bit about awaitable types in the previous chapter. But now we need to get a little bit more specific about what co_await
does and what an awaitable type is. The keyword co_await
is a unary operator, meaning that it takes a single argument. The argument we pass to co_await
needs to fulfill some requirements that we will explore in this section.
When we say co_await
in our code, we express that we are waiting for something that may or may not be ready for us. If it's not ready, co_await
suspends the currently executing coroutine and returns control back to its caller. When the asynchronous task has completed, it should transfer the control back to the coroutine originally waiting for the task to finish. From here on, I will typically refer to the awaiting function as the continuation.
Now consider the following expression:
co_await X{};
For this code to compile, X
needs to be an awaitable type. So...