kotlin-coroutines-flows

Provides Kotlin structured concurrency and Flow reactive programming patterns including StateFlow, SharedFlow, and testing via Turbine and TestDispatcher.

Updated Jul 27, 2026
One-click install
npx skills add https://github.com/kouiso/designdiff --skill kotlin-coroutines-flows-kouiso
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-coroutines-flows
Source: https://github.com/kouiso/designdiff/tree/main/.claude/skills/kotlin-coroutines-flows
Command: npx skills add https://github.com/kouiso/designdiff --skill kotlin-coroutines-flows-kouiso

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill simplifies writing asynchronous code in Kotlin by providing patterns and best practices for structured concurrency and reactive data streams using Coroutines and Flows.

Core Features & Use Cases

  • Structured Concurrency: Ensures coroutines are managed within defined scopes, preventing leaks and enabling proper cancellation.
  • Flow Management: Demonstrates how to create, combine, and operate on cold and hot Flows (StateFlow, SharedFlow) for reactive programming.
  • Error Handling & Cancellation: Provides strategies for robust error handling and graceful cancellation of coroutine operations.
  • Testing: Offers guidance on testing coroutines and Flows effectively.
  • Use Case: Efficiently handle background data fetching, UI state management, and real-time updates in Android and Kotlin Multiplatform applications.

Quick Start

Use the kotlin-coroutines-flows skill to understand how to launch a coroutine within a ViewModel's scope.

Frequently Asked Questions about kotlin-coroutines-flows

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

FAQPage Schema
How do I manage UI state with Kotlin StateFlow and SharedFlow in Android?

Manage UI state in Android by using Kotlin StateFlow for state exposure and SharedFlow for one-time events. This approach provides reactive data streams that handle configuration changes and ensure structured concurrency within ViewModel scopes.

What is the best way to handle structured concurrency and cancellation in Kotlin coroutines?

Handle structured concurrency in Kotlin by launching coroutines within defined scopes, which prevents memory leaks and enables proper cancellation. This approach ensures parent coroutines automatically cancel child operations when failures occur or scopes exit.

How do I test Kotlin Flows using Turbine and TestDispatcher?

Test Kotlin Flows using Turbine to collect emissions and TestDispatcher to control virtual time. This combination verifies asynchronous data streams, validates operators like debounce, and ensures predictable execution of concurrent operations.

When should I use supervisorScope versus parallel decomposition in Kotlin coroutines?

Use supervisorScope when child coroutines should fail independently without canceling siblings, and parallel decomposition for dividing tasks into concurrent chunks. Choosing the correct scope prevents cascading cancellations and optimizes parallel execution.

How do Flow operators like flatMapLatest and distinctUntilChanged handle reactive streams in Kotlin?

Flow operators like flatMapLatest and distinctUntilChanged handle reactive streams in Kotlin by transforming emissions and filtering duplicates. flatMapLatest cancels previous collectors when new values arrive, while distinctUntilChanged ignores consecutive duplicate emissions.

Does Kotlin coroutines structured concurrency support Kotlin Multiplatform (KMP) projects?

Structured concurrency and Flow-based reactive streams fully support Kotlin Multiplatform (KMP) projects. You can manage dispatcher switching, handle background data fetching, and implement real-time updates across different platforms using shared coroutine logic.