kotlin-coroutines-flows

Implements structured concurrency, Flow operators, StateFlow, and coroutine testing patterns for Kotlin projects.

Updated Mar 12, 2026
One-click install
npx skills add https://github.com/RavitejaKarra24/dotfiles --skill kotlin-coroutines-flows-ravitejakarra24
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-coroutines-flows
Source: https://github.com/RavitejaKarra24/dotfiles/tree/main/pi/.pi/agent/skills/kotlin-coroutines-flows
Command: npx skills add https://github.com/RavitejaKarra24/dotfiles --skill kotlin-coroutines-flows-ravitejakarra24

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing asynchronous Kotlin code without structured patterns leads to leaked coroutines, unhandled cancellation, and untestable reactive streams. This Skill provides proven patterns for coroutines and Flows in Android and Kotlin Multiplatform projects. ## Core Features & Use Cases - Structured Concurrency: Scope hierarchies, parallel decomposition with coroutineScope and async, and supervisorScope for independent child failures. - Flow Patterns: StateFlow for UI state, SharedFlow for one-time events, combining flows, debounce, retry with exponential backoff, and dispatcher selection. - Testing Support: Turbine-based StateFlow assertions, runTest with TestDispatcher, and fake repository implementations. - Use Case: When building a ViewModel that loads dashboard data from three repositories in parallel and exposes combined UI state, apply the async/await and combine patterns to produce a lifecycle-safe StateFlow. ## Quick Start Ask the assistant to refactor a ViewModel to load data in parallel with coroutines and expose the result as a StateFlow with proper error handling.

Frequently Asked Questions about kotlin-coroutines-flows

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

FAQPage Schema
How do I run coroutines in parallel in Kotlin?

Use coroutineScope with multiple async blocks to run suspending work concurrently, then call await on each Deferred result. This keeps the work structured so the parent scope waits for all children and propagates failures correctly.

How to convert a Flow to StateFlow in Android ViewModel?

Call stateIn on the Flow with viewModelScope, SharingStarted.WhileSubscribed(5000), and an initial value. The WhileSubscribed timeout keeps the upstream active briefly after subscribers leave, surviving configuration changes.

StateFlow vs SharedFlow in Kotlin, when to use which?

Use StateFlow for UI state that always has a current value and should be replayed to new collectors. Use SharedFlow for one-time events like snackbars or navigation that should not be re-delivered after rotation.

Does Dispatchers.IO work in Kotlin Multiplatform?

Dispatchers.IO is only available on JVM and Android. In KMP shared code, use Dispatchers.Default or Dispatchers.Main, which exist on all platforms, or inject the IO dispatcher through dependency injection.

How do I test StateFlow with Turbine?

Wrap the StateFlow collection in flow.test inside a runTest block, then assert each awaitItem emission in order. Turbine fails the test if unexpected emissions occur or expected ones never arrive.

Why is using GlobalScope in Kotlin coroutines bad?

GlobalScope launches coroutines with no parent, so they are never cancelled when the associated lifecycle ends, causing leaks. Use viewModelScope, lifecycleScope, or a custom structured scope tied to the component lifetime.