kotlin-coroutines

Implement Kotlin coroutines patterns for Android and Kotlin Multiplatform projects.

Updated Mar 17, 2026
One-click install
npx skills add https://github.com/kotlinknight/NutriSoloAndroid --skill kotlin-coroutines-kotlinknight
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-coroutines
Source: https://github.com/kotlinknight/NutriSoloAndroid/tree/main/.agents/skills/kotlin-coroutines
Command: npx skills add https://github.com/kotlinknight/NutriSoloAndroid --skill kotlin-coroutines-kotlinknight

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Kotlin coroutines can simplify asynchronous and non-blocking code, but managing dispatchers, scopes, and cancellation across Android and Kotlin Multiplatform can be error-prone without best practices.

Core Features & Use Cases

  • Guidance on dispatcher selection, structured concurrency, and lifecycle-safe patterns for Android ViewModels and KMP code.
  • Diagnosing common coroutine issues such as ANR, memory leaks, incorrect cancellation, and testability challenges.
  • Practical patterns for injecting dispatchers, avoiding GlobalScope, and using viewModelScope/lifecycleScope to manage work.

Quick Start

Run a coroutine-based data fetch in your ViewModel and handle lifecycle-safe dispatching.

Frequently Asked Questions about kotlin-coroutines

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

FAQPage Schema
How do I manage Kotlin coroutines with structured concurrency in Android ViewModels?

Manage Kotlin coroutines in Android ViewModels by applying structured concurrency with viewModelScope, ensuring work is cancelled when the ViewModel is cleared. Inject dispatchers properly to keep suspend functions testable and avoid GlobalScope memory leaks.

Why does my Kotlin coroutine cause an ANR or memory leak?

Kotlin coroutines cause ANRs or memory leaks when GlobalScope is used or dispatchers are incorrectly applied. Diagnose these issues by migrating to lifecycle-aware scopes like lifecycleScope and ensuring main-thread blocking operations run on background dispatchers.

What is the best way to inject dispatchers for Kotlin Multiplatform coroutines?

The best way to inject dispatchers for Kotlin Multiplatform coroutines is passing them as constructor parameters. This allows safe suspend function usage across platforms, makes testing easier by injecting test dispatchers, and ensures structured concurrency across typical network and UI tasks.

How do I handle cancellation and errors in Kotlin coroutines?

Handle cancellation and errors in Kotlin coroutines by leveraging structured concurrency scopes that automatically propagate exceptions. Ensure proper scope management to cancel child jobs when parent tasks fail, and use safe suspend functions that check for cancellation.

Does Kotlin coroutines structured concurrency work with Kotlin Multiplatform projects?

Structured concurrency works with Kotlin Multiplatform projects by sharing common coroutine logic across platforms. Apply lifecycle-aware patterns and dispatcher injection to manage UI updates and network calls reliably across shared KMP codebases.

How do I test Kotlin coroutines that use lifecycleScope and viewModelScope?

Test Kotlin coroutines using lifecycleScope and viewModelScope by injecting test dispatchers like StandardTestDispatcher. This validates cancellation, error handling, and structured concurrency behavior without relying on real Android lifecycle delays.