tezvyn:

What is a CoroutineDispatcher and when do you use each type?

Source: kotlinlang.orgintermediate

Tests your grasp of coroutine threading. A dispatcher manages which threads a coroutine runs on. Explain `Main` for UI, `Default` for CPU-intensive work, and `IO` for blocking operations. A red flag is mixing up `IO` and `Default` or using `Unconfined`.

This tests your understanding of coroutine threading models and performance implications. A `CoroutineDispatcher` determines which thread(s) execute a coroutine. A strong answer defines `Main` for UI updates, `Default` for CPU-intensive tasks (e.g., sorting a large list), and `IO` for blocking operations like network calls or file access. The key difference is their underlying thread pool size and design. A common mistake is using `Default` for network calls, which can starve the CPU-bound thread pool.

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 CoroutineDispatcher and when do you use each type? · Tezvyn