# Kotlin Continuations

DevFeed: [Kotlin Continuations](<https://devfeed.tech/articles/kotlin-continuations-27465.md>)

Original publisher: [Read original article](<https://jorgecastilloprz.github.io/digging-into-kotlin-continuations>)

Author: Jorge Castillo

Published: 2020-09-03T11:00:00Z

Content type: article

Language: en

Sources: [Jorge Castillo](<https://devfeed.tech/sources/jorge-castillo.md>)

Topics: [suspend function](<https://devfeed.tech/topics/suspend-function.md>), [Coroutines](<https://devfeed.tech/topics/coroutines.md>), [async](<https://devfeed.tech/topics/async.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [IntelliJ IDEA](<https://devfeed.tech/topics/intellij-idea.md>)

Tags: [1-3](<https://devfeed.tech/tags/1-3.md>), [android](<https://devfeed.tech/tags/android.md>), [api](<https://devfeed.tech/tags/api.md>), [apis](<https://devfeed.tech/tags/apis.md>), [arrow](<https://devfeed.tech/tags/arrow.md>), [async](<https://devfeed.tech/tags/async.md>), [asynchronous](<https://devfeed.tech/tags/asynchronous.md>), [blocking](<https://devfeed.tech/tags/blocking.md>), [boolean](<https://devfeed.tech/tags/boolean.md>), [bridge](<https://devfeed.tech/tags/bridge.md>), [bytecode](<https://devfeed.tech/tags/bytecode.md>), [callback](<https://devfeed.tech/tags/callback.md>), [cancellation](<https://devfeed.tech/tags/cancellation.md>), [class](<https://devfeed.tech/tags/class.md>), [clicks](<https://devfeed.tech/tags/clicks.md>), [compile](<https://devfeed.tech/tags/compile.md>), [control](<https://devfeed.tech/tags/control.md>), [flow](<https://devfeed.tech/tags/flow.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [program](<https://devfeed.tech/tags/program.md>)

## AI overview

Kotlin compiles `suspend` functions into continuation-passing calls: each receives a `Continuation` that carries coroutine context and resumes execution with a success or failure result. Generated state machines and saved stack-frame state let execution pause at suspension points and continue later. Java can call the generated functions with an explicit continuation, but Kotlin's `Result` inline class complicates that route; the excerpt also describes bridging through `CompletableFuture`, calling coroutine builders from Java, or exposing Kotlin wrapper functions. For callback APIs, `suspendCoroutine` can resume a one-shot continuation, so listeners must be detached after use. The excerpt recommends `suspendCancellableCoroutine` when cancellation cleanup is needed; for repeated user events, it points to stream-based approaches such as `callbackFlow` or Arrow Fx `Stream.cancellable`.

## Source excerpt

Continuations represent the rest of a program. They are a form of control flow.