kotlin-concurrency-expert

Identify and remediate Kotlin Coroutine misuse in Android projects.

1|Updated Sep 7, 2025
One-click install
npx skills add https://github.com/sahuadarsh0/Wallet --skill kotlin-concurrency-expert-sahuadarsh0
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-concurrency-expert
Source: https://github.com/sahuadarsh0/Wallet/tree/main/.cursor/skills/kotlin-concurrency-expert
Command: npx skills add https://github.com/sahuadarsh0/Wallet --skill kotlin-concurrency-expert-sahuadarsh0

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Complex coroutine usage in Android can cause lifecycle leaks, race conditions, and unresponsive UI.

Core Features & Use Cases

  • Structured Concurrency: Enforces scoped coroutine work to lifecycle-aware boundaries.
  • Lifecycle Safety: Guides replacement of GlobalScope and improper dispatchers with viewModelScope/lifecycleScope.
  • Bug Remediation: Helps identify and fix common coroutine-related issues like cancellation, and thread-safety.
  • Use Case: Refactor a mis-scoped IO operation in a ViewModel to use appropriate scope and error handling.

Quick Start

Review a Kotlin Android project to identify coroutine misuse, apply structured concurrency, and improve lifecycle safety.

Frequently Asked Questions about kotlin-concurrency-expert

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

FAQPage Schema
How do I fix Kotlin coroutine lifecycle leaks in Android?

Fix Kotlin coroutine lifecycle leaks by enforcing structured concurrency within viewModelScope or lifecycleScope. This ensures coroutines are automatically cancelled when the Android lifecycle owner is destroyed, preventing memory leaks and UI freezing.

What is structured concurrency and how does it apply to Android ViewModels?

Structured concurrency in Android ViewModels requires scoping background work to lifecycle-aware boundaries like viewModelScope. It guarantees that launched coroutines are properly tracked and cancelled when the ViewModel clears, avoiding unmanaged background threads and race conditions.

How do I refactor improper dispatchers in Kotlin coroutines for IO operations?

Refactor improper dispatchers in Kotlin coroutines by applying dispatcher injection to switch execution contexts correctly. Move IO operations to appropriate scopes with explicit dispatcher management, ensuring safe cancellation and testability without blocking the UI thread.

Can I test Android coroutines that use hard-coded dispatcher scopes?

Testing Android coroutines with hard-coded dispatchers is difficult. You must apply dispatcher injection to replace real dispatchers with test controllers. This enables lifecycle-aware collection and safe cancellation testing without relying on actual IO or UI threads.

Why does my Android UI freeze during background coroutine work?

Your Android UI freezes during background coroutine work because improper dispatchers or mis-scoped operations are blocking the UI thread. Identify coroutine misuse and apply structured concurrency to shift heavy tasks to viewModelScope with correct dispatcher injection.

What are the limitations of using GlobalScope for Android coroutines?

The limitation of using GlobalScope for Android coroutines is the lack of lifecycle safety, causing operations to outlive their owners and trigger memory leaks. Replace GlobalScope with lifecycleScope or viewModelScope to enforce structured concurrency and safe cancellation.