Solution: Coroutines Under the Hood

See the solution to the coroutines under the hood problem.

We'll cover the following

Solution

We could start the function from two places: either from the beginning (in the case of a first call), or the point after suspension (in the case of resuming from continuation). To identify the current state, we use a field called a label. At the start, it is 0. Therefore, the function will start from the beginning. However, it's set to the next state before each suspension point so that we start from just after the suspension point after a resume.

Get hands-on with 1400+ tech skills courses.