🐦 Kotlin
Intermediate
What is a suspend function in Kotlin?
Answer
A suspend function is a function that can pause its execution without blocking the underlying thread and resume later when its result is ready. It is marked with the suspend modifier and can only be called from another suspend function or a coroutine builder. Under the hood, the Kotlin compiler transforms suspend functions into state machines using continuation-passing style. This transformation allows non-blocking I/O — when a suspend function is waiting for a network response, the thread is free to do other work. This is fundamentally different from blocking I/O where the thread is stuck waiting.
Previous
What are Kotlin Coroutines?
Next
What is the difference between launch and async in Kotlin coroutines?