Implementing a Rudimentary Task Type (Part 2)
Explore how to implement a basic Task type in C++ coroutines focusing on resuming awaiting coroutines without causing stack overflow. Understand the use of coroutine handles and symmetric transfer optimization. Learn to extend the Task template specialization to support void-returning tasks, enhancing your asynchronous programming skills with coroutines.
We'll cover the following...
Resuming an awaiting coroutine
When the asynchronous task has been completed, it should transfer the control back to the coroutine, waiting for the task to finish. To resume this continuation, the Task object needs the coroutine_handle to the continuation coroutine. This handle was passed to the Task object’s await_suspend() function, and conveniently we made sure to save that handle into the promise object:
The final_suspend() function is responsible for suspending at the final suspend point of this coroutine and transferring execution to the awaiting coroutine. This is the relevant part of the Promise reproduced for your convenience:
To begin with, returning false ...