The Workflow
Discover a dynamic aspect of coroutines called workflow.
We'll cover the following...
The compiler transforms your coroutine and runs two workflows: the outer promise workflow and the inner awaiter workflow.
The promise workflow
When you use co_yield
, co_await
, or co_return
in a function, the function becomes a coroutine, and the compiler transforms its body to something equivalent to the following lines.
Press + to interact
{Promise prom;co_await prom.initial_suspend();try {<function body having co_return, co_yield, or co_wait>}catch (...) {prom.unhandled_exception();}FinalSuspend:co_await prom.final_suspend();}
The compiler automatically runs the transformed code using the functions of the promise object. In short, I call this workflow the promise workflow. Here are the main steps of this workflow: