kotlin-coroutines-kmp-dispatchers
Installation
SKILL.md
Coroutines and Dispatchers in KMP
Use this skill when implementing or reviewing coroutine concurrency, dispatcher choice, or main-thread safety across KMP targets.
Goals
- Never block Main with disk/network/CPU-heavy work
- Correct
Dispatchers.Mainbehavior on Android and Kotlin/Native - Testable code via injectable dispatchers
- Safe delivery of UI state to Compose and SwiftUI
Prefer official defaults
- Use structured concurrency (
coroutineScope,supervisorScope, ViewModel/presenterscope) — no unstructuredGlobalScopefor app work. - Run IO/CPU work on
Dispatchers.Defaultor an injected IO dispatcher; switch to Main only for UI-facing emission. - Prefer repository / data APIs that are main-safe (safe to call from Main; they move work internally).
- Inject
CoroutineDispatcher(or a smallDispatcherProvider) in types you unit-test.
Docs: https://kotlinlang.org/docs/coroutines-guide.html · https://kotlinlang.org/docs/multiplatform/compose-compatibility-and-versioning.html (lifecycle/coroutines artifacts as applicable)