kotlin-coroutines-skill

Analyze and fix Kotlin coroutine and Flow code for correctness, safety, and testability.

11|2|Updated Sep 8, 2015
One-click install
npx skills add https://github.com/jitrapon/astro-mobile --skill kotlin-coroutines-skill
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-coroutines-skill
Source: https://github.com/jitrapon/astro-mobile/tree/main/.claude/skills/kotlin-coroutines-skill
Command: npx skills add https://github.com/jitrapon/astro-mobile --skill kotlin-coroutines-skill

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers identify and fix correctness, safety, and testability issues in Kotlin coroutine-based code, especially where asynchronous work becomes hard to reason about or difficult to cancel.

Core Features & Use Cases

  • Structured Concurrency Guidance: Choose the right scope and preserve parent-child cancellation behavior.
  • Dispatcher and Main-Safety Review: Prevent blocking work on the wrong thread and make suspend functions safe to call from UI code.
  • Flow and Lifecycle Best Practices: Improve state handling, event delivery, and Android collection patterns.
  • Testing and Reliability Support: Replace flaky coroutine tests with deterministic virtual-time patterns.
  • Use Case: Review a ViewModel, repository, or shared KMP module to catch scope leaks, misuse of async, cancellation bugs, flow collection mistakes, and test flakiness before they ship.

Quick Start

Ask for a coroutine code review that pinpoints the risk, shows the problematic code, and rewrites it using structured concurrency, correct dispatchers, lifecycle-aware flow handling, and deterministic tests.

Frequently Asked Questions about kotlin-coroutines-skill

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

FAQPage Schema
How do I fix Kotlin coroutines cancellation bugs and scope leaks in my Android ViewModel?

To fix Kotlin coroutines cancellation bugs and scope leaks, apply structured concurrency by choosing the right scope and preserving parent-child cancellation behavior. This prevents orphaned background work when the parent scope clears.

What is the best way to make Kotlin suspend functions main-safe for Android UI code?

Making Kotlin suspend functions main-safe requires dispatcher injection to ensure blocking work runs on the correct background thread. This prevents blocking the main thread and makes suspend functions safe to call directly from Android UI code.

How do I write deterministic Kotlin coroutines and Flow tests without flakiness?

Writing deterministic Kotlin coroutines and Flow tests requires replacing real-time delays with virtual-time test patterns. This approach controls the dispatcher scheduler, ensuring tests run instantly and reliably without flaky timing dependencies.

Does this approach support reviewing Kotlin Multiplatform (KMP) shared modules for concurrency safety?

Yes, the approach supports reviewing Kotlin Multiplatform (KMP) shared modules for concurrency safety. It analyzes shared KMP code to catch dispatcher misuse, Flow collection mistakes, and cancellation bugs across Android and backend concurrency scenarios.

Why does my Kotlin Flow collection leak when the Android lifecycle changes?

Kotlin Flow collection leaks during Android lifecycle changes occur when collection is not lifecycle-aware. Implementing lifecycle-aware Flow collection patterns ensures state handling and event delivery pause and cancel correctly when the view destroys.

When should I not use GlobalScope for Kotlin coroutines?

You should not use GlobalScope for Kotlin coroutines when work needs to be tied to a specific lifecycle or caller. Using structured concurrency with custom scopes prevents uncancelable leaks and ensures operations fail predictably.