kotlin-coroutines

Guide Kotlin Coroutines code for structured concurrency, Flow operators, and testing.

7|2|Updated Feb 23, 2026
One-click install
npx skills add https://github.com/javiercamarenatriguero/android-skills --skill kotlin-coroutines-javiercamarenatriguero
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-coroutines
Source: https://github.com/javiercamarenatriguero/android-skills/tree/main/kotlin-coroutines
Command: npx skills add https://github.com/javiercamarenatriguero/android-skills --skill kotlin-coroutines-javiercamarenatriguero

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides best practices for writing correct, performant, and idiomatic Kotlin Coroutines code, addressing common pitfalls in asynchronous programming.

Core Features & Use Cases

  • Structured Concurrency: Learn to manage coroutine lifecycles effectively using scopes like viewModelScope and lifecycleScope.
  • Flow Operators: Understand and apply operators for transforming, filtering, and combining asynchronous data streams.
  • State Management: Implement robust state handling with StateFlow and event emission with SharedFlow.
  • Error Handling: Master safe error handling strategies for both suspend functions and Flows.
  • Testing: Write reliable tests for coroutine-based code using runTest and Turbine.

Quick Start

Use the kotlin-coroutines skill to refactor the provided code snippet to use structured concurrency with viewModelScope.

Frequently Asked Questions about kotlin-coroutines

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

FAQPage Schema
How do I manage coroutine lifecycles effectively using structured concurrency in Kotlin?

Structured concurrency in Kotlin manages coroutine lifecycles by tying them to specific scopes like viewModelScope and lifecycleScope, ensuring operations are canceled when the scope ends. This prevents memory leaks and maintains correct state.

What is the best way to handle asynchronous state and events using Kotlin Flow?

The best way to handle asynchronous state in Kotlin is using StateFlow for robust state management, while SharedFlow handles event emission. These Flow operators transform, filter, and combine reactive data streams for correct performant state handling.

How do I test Kotlin coroutines and asynchronous data streams reliably?

Test Kotlin coroutines reliably by using the runTest testing utility to control virtual time and Turbine to collect Flow emissions. These tools validate asynchronous operations and reactive stream behavior without flakiness.

Does this Kotlin coroutines guide cover error handling strategies for suspend functions and Flows?

Yes, this covers safe error handling strategies for both suspend functions and Flows. It addresses common pitfalls in asynchronous programming by guiding correct error propagation and recovery within coroutine scopes and reactive streams.

Why do my Kotlin coroutines leak memory or lose state when the screen changes?

Kotlin coroutines leak memory or lose state when they are not tied to correct lifecycle scopes. Applying structured concurrency with viewModelScope or lifecycleScope ensures coroutine cancellation and proper state management during screen changes.