Kotlin Coroutine Internals: Suspension, Continuation, CPS

This post explains how coroutines work, referencing the design proposal Kotlin Proposals - Coroutines. Coroutine The proposal describes a coroutine in one sentence as an instance of suspendable computation. The essential trait of a coroutine is its ability to suspend. So what exactly does “suspendable” mean? Suspension According to the proposal, suspendable means a coroutine can pause execution on the current thread, yield the thread so another coroutine can run, and later resume—possibly on a different thread. ...

July 7, 2023 · 8 min