A Function with a State and Resumed Value
Explore how Kotlin coroutines manage state within suspending functions by storing variables in continuations. Understand how functions resume with values or exceptions and how these outcomes are handled under the hood.
We'll cover the following...
We'll cover the following...
A function with a state
If a function has some state (like local variables or parameters) that we need to restore after suspension, this state needs to be kept in the function’s continuation. Let’s consider the following function.
Here, counter is needed in two states (for a label equal to 0 and 1), so it ...