kotlin-coroutines-flows

Implements Kotlin coroutines and Flow patterns for structured concurrency, reactive streams, and testing.

1|Updated Oct 11, 2025
One-click install
npx skills add https://github.com/ibytechaos/claude --skill kotlin-coroutines-flows-ibytechaos
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-coroutines-flows
Source: https://github.com/ibytechaos/claude/tree/main/plugins/everything-claude-code/skills/kotlin-coroutines-flows
Command: npx skills add https://github.com/ibytechaos/claude --skill kotlin-coroutines-flows-ibytechaos

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing asynchronous code in Kotlin often leads to leaked coroutines, unhandled cancellation, and untestable reactive streams. This Skill provides proven patterns for structured concurrency, Flow-based data streams, and coroutine testing in Android and Kotlin Multiplatform projects. ## Core Features & Use Cases - Structured Concurrency: Enforces scope hierarchies with viewModelScope, coroutineScope, and supervisorScope instead of GlobalScope, plus parallel decomposition with async/await. - Flow Patterns: Covers StateFlow for UI state, SharedFlow for one-time events, combining multiple flows, debounce, retry with exponential backoff, and dispatcher selection. - Testing Support: Demonstrates Turbine-based StateFlow assertions, runTest with TestDispatcher, and fake Flow repositories. - Use Case: When building an Android dashboard screen that loads items, stats, and profile in parallel and exposes them as a combined StateFlow, apply these patterns to get cancellation-safe, lifecycle-aware, testable code. ## Quick Start Ask the AI to refactor a ViewModel that uses GlobalScope into structured concurrency with StateFlow and add a Turbine test for it.

Frequently Asked Questions about kotlin-coroutines-flows

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

FAQPage Schema
How do I use StateFlow in an Android ViewModel?

Convert a cold Flow to StateFlow using stateIn with viewModelScope, SharingStarted.WhileSubscribed(5000), and an initial value. This keeps the upstream active for 5 seconds after the last subscriber leaves, surviving configuration changes.

How to run multiple suspend functions in parallel with Kotlin coroutines?

Wrap async calls inside a coroutineScope block and await their results. This gives structured concurrency where all children complete or cancel together, unlike launching separate unstructured jobs.

What is the difference between StateFlow and SharedFlow?

StateFlow holds a current value and suits UI state, while SharedFlow is for one-time events like snackbars or navigation. Use MutableSharedFlow exposed as SharedFlow for effects collected in a LaunchedEffect.

Does Dispatchers.IO work in Kotlin Multiplatform?

Dispatchers.IO is JVM and Android only. In KMP, use Dispatchers.Default or Dispatchers.Main which are available on all platforms, or provide the IO dispatcher via dependency injection.

How do I test Kotlin Flows with Turbine?

Use runTest and call .test on the StateFlow, then assert each awaitItem in emission order. Combine with advanceUntilIdle and fake repositories backed by MutableStateFlow to control emitted values.

Why should I avoid GlobalScope in Kotlin coroutines?

GlobalScope launches coroutines with no structured cancellation, causing leaks when the lifecycle owner is destroyed. Use viewModelScope in ViewModels or LaunchedEffect in composables so work is cancelled automatically.