kotlin-coroutines

Reviews and writes Kotlin coroutine code covering dispatchers, scopes, cancellation, and exception handling.

1|Updated Jun 1, 2026
One-click install
npx skills add https://github.com/chmonya-inc/dnd-manager --skill kotlin-coroutines-chmonya-inc
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: kotlin-coroutines
Source: https://github.com/chmonya-inc/dnd-manager/tree/main/.agents/skills/kotlin-coroutines
Command: npx skills add https://github.com/chmonya-inc/dnd-manager --skill kotlin-coroutines-chmonya-inc

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Coroutine bugs like ANRs, memory leaks from GlobalScope, and silently swallowed CancellationExceptions are hard to spot in code review. This Skill provides a structured diagnostic and rule set for writing, reviewing, and debugging coroutine code in Android and Kotlin Multiplatform projects. ## Core Features & Use Cases - Symptom-based diagnosis: Triage table mapping symptoms (ANR, zombie coroutines, broken cancellation) to root causes and fixes. - Architecture rules: Enforces main-safe suspend functions, dispatcher injection via DispatcherProvider, and correct scope ownership (viewModelScope vs. stored scopes vs. WorkManager). - Testing guidance: Covers runTest, StandardTestDispatcher vs. UnconfinedTestDispatcher, and TestDispatcherProvider setup. - Use Case: When reviewing a ViewModel that exposes a suspend fun for business logic or a repository that stores a CoroutineScope, the Skill flags the anti-pattern, explains why it is harmful, and provides the corrected implementation. ## Quick Start Ask the assistant to review your Kotlin repository or ViewModel code for coroutine issues such as GlobalScope usage, hardcoded dispatchers, or swallowed CancellationException.

Frequently Asked Questions about kotlin-coroutines

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix ANR caused by coroutines on the main thread?▼

Move blocking work off the main thread by wrapping it in withContext(Dispatchers.IO) inside the suspend function itself. The function doing blocking work owns the dispatcher switch, so callers never need to change dispatchers.

What is the difference between viewModelScope and GlobalScope?▼

viewModelScope is lifecycle-bound and cancels automatically when the ViewModel is cleared, while GlobalScope creates unstructured, leak-prone coroutines with no cancellation owner. Never use GlobalScope; inject a CoroutineScope or use viewModelScope instead.

Why does catching Exception break coroutine cancellation?▼

Catching Exception or Throwable also catches CancellationException, which silently breaks structured cancellation. Catch only specific types like IOException, and always rethrow CancellationException.

Should I use StandardTestDispatcher or UnconfinedTestDispatcher in runTest?▼

StandardTestDispatcher queues coroutines until you call advanceUntilIdle(), giving precise control over execution order and delays. UnconfinedTestDispatcher runs coroutines eagerly, which is simpler for basic state tests but can hide ordering bugs.

Can a repository store its own CoroutineScope for background work?▼

Storing a CoroutineScope in a repository is an anti-pattern because cancellation and error reporting become invisible. Expose suspend functions and let the caller own the scope, or use WorkManager or a named application-scoped class for work that must outlive the caller.