kotlin-coroutines

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

Updated Jul 1, 2026
One-click install
npx skills add https://github.com/w0lzard/Wolzard-s-Marketplace --skill kotlin-coroutines-w0lzard
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-coroutines
Source: https://github.com/w0lzard/Wolzard-s-Marketplace/tree/main/plugins/personal-skills/skills/kotlin-coroutines
Command: npx skills add https://github.com/w0lzard/Wolzard-s-Marketplace --skill kotlin-coroutines-w0lzard

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Coroutine bugs like ANRs, memory leaks from GlobalScope, silently swallowed CancellationExceptions, and untestable hardcoded dispatchers are hard to spot in review. This Skill provides a structured diagnostic and rule set for writing, reviewing, and debugging coroutine code in Android and KMP projects. ## Core Features & Use Cases - Symptom-based diagnosis: Maps common symptoms (UI freezes, zombie coroutines, broken cancellation) to likely causes and concrete fixes. - Architecture rules: Enforces main-safe suspend functions, injected dispatchers via DispatcherProvider, proper scope ownership, and structured concurrency with coroutineScope/supervisorScope. - Testing guidance: Covers runTest, StandardTestDispatcher vs UnconfinedTestDispatcher, and TestDispatcherProvider setup. - Use Case: While reviewing a ViewModel that catches generic Exception and launches from a stored CoroutineScope in a repository, the Skill flags both violations, explains why they break cancellation and lifecycle ownership, and proposes the correct refactor. ## Quick Start Ask the assistant to review your Kotlin coroutine code for dispatcher, scope, cancellation, and exception handling issues using the kotlin-coroutines skill.

Frequently Asked Questions about kotlin-coroutines

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

FAQPage Schema
How do I choose the right CoroutineDispatcher in Kotlin?

Use Dispatchers.Main for UI updates, Dispatchers.IO for blocking I/O like network and database calls, and Dispatchers.Default for CPU-intensive work. Inject dispatchers via a DispatcherProvider interface instead of hardcoding them so tests can substitute test dispatchers.

How do I fix GlobalScope memory leaks in Android?

Replace GlobalScope with a lifecycle-bound scope such as viewModelScope in ViewModels or lifecycleScope in UI components. For work that must outlive the screen, use WorkManager or an explicit Application-scoped class with named start and stop methods.

Why does catching Exception break coroutine cancellation?

Catching generic Exception or Throwable also catches CancellationException, which silently breaks structured cancellation so parent scopes cannot stop the coroutine. Catch only specific types like IOException, and always rethrow CancellationException.

Should I use StandardTestDispatcher or UnconfinedTestDispatcher with 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 I use runCatching inside suspend functions?

No, runCatching catches all Throwable including CancellationException, breaking structured concurrency. Use a suspendRunCatching utility that rethrows CancellationException, or use try/catch with specific exception types instead.

When should a repository expose suspend fun instead of launching its own coroutine?

Repositories should expose suspend functions and let the caller own the scope, because a stored CoroutineScope hides cancellation, error reporting, and lifecycle ownership. Only UI state holders using lifecycle-bound scopes for UI events should launch from non-suspending methods.