kotlin-concurrency-expert

Analyze and remediate Kotlin coroutine usage in Android projects.

Updated Mar 9, 2025
One-click install
npx skills add https://github.com/rock-hu/vitamin-compose --skill kotlin-concurrency-expert-rock-hu
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-concurrency-expert
Source: https://github.com/rock-hu/vitamin-compose/tree/main/.github/skills/kotlin-concurrency-expert
Command: npx skills add https://github.com/rock-hu/vitamin-compose --skill kotlin-concurrency-expert-rock-hu

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill helps Android teams ensure safe, structured concurrency by reviewing and remediating coroutine usage, lifecycle handling, and thread safety.

Core Features & Use Cases

  • Audit and remediate coroutine usage across Android components to prevent leaks and race conditions.
  • Replace GlobalScope and improper job management with lifecycle-aware scopes like viewModelScope and lifecycleScope.
  • Enforce best practices: StateFlow encapsulation, dispatcher injection for testability, and proper cancellation handling.
  • Use Case: A ViewModel launches long-running work; the skill will propose scoped launch patterns and cancellation handling to avoid leaks.

Quick Start

Ask the Kotlin Concurrency Expert to review a Kotlin Android module's coroutine usage and return a concrete remediation plan.

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 leaks in Android ViewModel and Fragment lifecycles?

To fix Kotlin coroutine leaks in Android ViewModel and Fragment lifecycles, replace GlobalScope with lifecycle-aware scopes like viewModelScope and lifecycleScope to ensure structured concurrency and automatic cancellation upon component destruction.

What is the best way to replace GlobalScope usage in Android projects for structured concurrency?

The best way to replace GlobalScope usage for structured concurrency is to adopt lifecycle-aware scopes such as viewModelScope or lifecycleScope, ensuring that coroutine jobs are properly scoped and canceled to prevent memory leaks.

How do I use repeatOnLifecycle to safely collect StateFlow in Android Fragments?

To safely collect StateFlow in Android Fragments, use repeatOnLifecycle to configure the flow collection within the appropriate lifecycle state, ensuring thread safety and preventing crashes when the view becomes inactive.

Why should I inject dispatchers in Kotlin coroutines for Android testability?

You should inject dispatchers in Kotlin coroutines to improve Android testability by allowing you to easily swap execution threads during unit testing, ensuring deterministic behavior and verifying structured concurrency without relying on real asynchronous execution.

Can this skill audit an entire Android module's coroutine usage and return a remediation plan?

Yes, this skill can audit an entire Android module's coroutine usage by analyzing lifecycle handling, scope management, and thread safety, returning a concrete remediation plan to enforce best practices across ViewModel and Activity components.