🧵 How to Answer Like a Kotlin Coroutine Expert: Kotlin Coroutine Suspension Under the Hood | by Shbazhenov | Mar, 2025

Take this simple example:

suspend fun functionA(param: Int): String {
return "hello $param"
}

When compiled, the Kotlin compiler transforms it to something like:

public static final Object functionA(int param, Continuation super String> $completion) {
return "hello " + param;
}
  • An extra parameter of type Continuation was added.
  • The return type changed from String to Object (or Any? in Kotlin), because:
  • If the function completes synchronously, it returns the result (e.g., "hello 5")
  • If it suspends, it returns a special marker: COROUTINE_SUSPENDED

This transformation enables the compiler to treat the function as a suspendable computation, not just a regular method call.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.