A Peek at Continuations

Preserving the state

Methods marked with the suspend annotation may return data. However, coroutines may suspend execution and may switch threads. How in the world does the state get preserved and propagated between threads?

To explore this further, let’s take a look at an example that brings out this concern clearly. Instead of creating .kts files, we’ll create .kt files so it’s easy to compile to Java bytecode and examine.

Get hands-on with 1200+ tech skills courses.