Solution: What is stored by a continuation?
A continuation must store all the coroutine’s variables that are used after the suspension point. So, in this case it needs to store c
and a
(it does not need to store the value b
because it is not used after the suspension). A continuation must also store the label that marks the point at which the coroutine should be resumed. In this case, this is the label 2 for function a
, and 1 for main
.
Here is a simplified continuation structure:
{
I$0: 12345,
label: 2,
completion: {
I$0: "ABC"
label: 1,
completion: ...
}
}
Marcin Moskala is a highly experienced developer and Kotlin instructor as the founder of Kt. Academy, an official JetBrains partner specializing in Kotlin training, Google Developers Expert, known for his significant contributions to the Kotlin community. Moskala is the author of several widely recognized books, including "Effective Kotlin," "Kotlin Coroutines," "Functional Kotlin," "Advanced Kotlin," "Kotlin Essentials," and "Android Development with Kotlin."
Beyond his literary achievements, Moskala is the author of the largest Medium publication dedicated to Kotlin. As a respected speaker, he has been invited to share his insights at numerous programming conferences, including events such as Droidcon and the prestigious Kotlin Conf, the premier conference dedicated to the Kotlin programming language.