← ClaudeAtlas

kotlin-coroutineslisted

Write data-safe asynchronous Kotlin with coroutines, Flow, and structured concurrency on Android. Use when fixing coroutine cancellation or leak bugs, choosing dispatchers (Default/IO/Main), designing suspend functions, modeling streams with Flow/StateFlow/SharedFlow, scoping work to viewModelScope/lifecycleScope, handling exceptions with CoroutineExceptionHandler/supervisorScope, or converting callback/RxJava APIs to coroutines. Covers Kotlin 2.x, kotlinx.coroutines structured concurrency discipline, and the Android main-safety contract.
eric-sabe/engsys · ★ 1 · AI & Automation · score 67
Install: claude install-skill eric-sabe/engsys
# Kotlin Coroutines Review, fix, and write concurrent Kotlin targeting Kotlin 2.1+ and kotlinx.coroutines 1.9+. Apply structured concurrency, correct dispatcher choice, and cooperative cancellation with minimal behavior changes. This is the Kotlin equivalent of Swift's structured-concurrency discipline: scopes are the unit of lifetime, cancellation is cooperative, and main-safety is non-negotiable. ## Contents - [Triage Workflow](#triage-workflow) - [Structured Concurrency](#structured-concurrency) - [Coroutine Scopes](#coroutine-scopes) - [Dispatchers and Main-Safety](#dispatchers-and-main-safety) - [Cancellation](#cancellation) - [Exception Handling](#exception-handling) - [Flow](#flow) - [StateFlow and SharedFlow](#stateflow-and-sharedflow) - [Bridging Callback APIs](#bridging-callback-apis) - [Common Mistakes](#common-mistakes) - [Review Checklist](#review-checklist) ## Triage Workflow When diagnosing a coroutine issue, follow this sequence: ### Step 1: Capture context - Identify the scope the coroutine runs in (`viewModelScope`, `lifecycleScope`, a custom `CoroutineScope`, or an unscoped `GlobalScope` — a red flag). - Identify the dispatcher in effect and whether the work is CPU-bound, IO-bound, or UI-bound. - Determine whether the work must survive configuration changes / navigation, or should be cancelled with the screen. - Copy any stack trace; note whether it is a `CancellationException` (normal) or a real failure. ### Step 2: Apply the smallest safe