kotlin-coroutines

Diagnose and fix Kotlin coroutine bugs in Android projects.

1|Updated Jun 24, 2026
One-click install
npx skills add https://github.com/eric-sabe/engsys --skill kotlin-coroutines-eric-sabe
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-coroutines
Source: https://github.com/eric-sabe/engsys/tree/main/stacks/lang/kotlin/skills/kotlin-coroutines
Command: npx skills add https://github.com/eric-sabe/engsys --skill kotlin-coroutines-eric-sabe

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill eliminates common coroutine bugs like memory leaks, unhandled cancellations, main thread blocking, and incorrect Flow state modeling that cause unstable Android apps and hours of debugging, replacing guesswork with structured concurrency best practices.

Core Features & Use Cases

  • Bug Fixing & Review: Diagnose and fix coroutine cancellation leaks, GlobalScope misuse, and swallowed CancellationExceptions.
  • Best Practice Guidance: Choose correct dispatchers for CPU/IO/UI work, design main-safe suspend functions, and scope work to viewModelScope/lifecycleScope.
  • Flow & API Bridging: Model UI state with StateFlow, one-shot events with SharedFlow, and convert legacy callback/RxJava APIs to coroutines.
  • Use Case Example: If your app crashes on screen rotation due to leaked coroutines, or has jank from network calls running on the main thread, this Skill provides step-by-step fixes aligned with Kotlin 2.x and kotlinx.coroutines 1.9+ standards.

Quick Start

Use the kotlin-coroutines skill to review your ViewModel's data loading coroutine, fix any lifecycle or dispatcher issues, and ensure all async work is properly scoped and main-safe.

Frequently Asked Questions about kotlin-coroutines

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

FAQPage Schema
How do I fix Kotlin coroutine memory leaks in Android after screen rotation?

Fix Kotlin coroutine memory leaks by scoping asynchronous work to viewModelScope or lifecycleScope, ensuring structured concurrency prevents leaked coroutines during screen rotation. Replace GlobalScope misuse with lifecycle-aware scopes to automatically cancel orphaned jobs and stop memory leaks.

Why does my Android app jank when running network calls with Kotlin coroutines?

Android app jank occurs when Kotlin coroutines block the main thread with network calls, requiring proper dispatcher selection to offload IO work. Use Dispatchers.IO for network requests and design main-safe suspend functions to prevent UI freezing.

What is the best way to model UI state with Kotlin Flow in Android ViewModels?

The best way to model UI state with Kotlin Flow is using StateFlow for synchronous UI rendering and SharedFlow for one-shot events. This approach correctly handles asynchronous stream modeling and lifecycle compliance within Android ViewModels.

Does this coroutine debugging approach work with Kotlin 2.1 and kotlinx.coroutines 1.9?

Yes, this coroutine debugging approach works with Kotlin 2.1+ and kotlinx.coroutines 1.9+, specifically targeting Android projects to enforce structured concurrency, cooperative cancellation, and proper exception handling standards.

How to convert legacy callback APIs to Kotlin coroutines without swallowing CancellationException?

Convert legacy callback APIs to Kotlin coroutines using suspendCancellableCoroutine, ensuring you properly propagate CancellationException instead of swallowing it. This prevents unhandled cancellations and maintains cooperative cancellation discipline during API bridging.

When should I not use GlobalScope for Kotlin coroutines in Android?

You should not use GlobalScope for Kotlin coroutines in Android when operations are tied to lifecycle components, as it breaks structured concurrency and causes memory leaks. Use viewModelScope or lifecycleScope to ensure automatic cancellation and proper exception handling.