tezvyn:

What is a Kotlin `suspend` function and how does it work?

Source: kotlinlang.orgbeginner

Tests your grasp of Kotlin's non-blocking concurrency. A great answer defines a suspend function as pausable, states its two calling rules (from another suspend function or coroutine builder), and mentions the compiler's CPS transformation.

This question tests your fundamental grasp of how Kotlin coroutines achieve non-blocking concurrency. A strong answer defines a `suspend` function as one that can be paused and resumed without blocking a thread. It then states the two key rules: it can only be called from another suspend function or a coroutine builder. Finally, it explains that the compiler implements this via Continuation-Passing Style (CPS), adding a hidden `Continuation` parameter to manage state. A common mistake is equating `suspend` with thread blocking.

Read the original → kotlinlang.org

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

What is a Kotlin `suspend` function and how does it work? · Tezvyn