kotlin-coroutines-flows

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

Updated Mar 18, 2026
One-click install
npx skills add https://github.com/freedom909/real-estate-saas --skill kotlin-coroutines-flows-freedom909
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: kotlin-coroutines-flows
Source: https://github.com/freedom909/real-estate-saas/tree/main/.trae/skills/kotlin-coroutines-flows
Command: npx skills add https://github.com/freedom909/real-estate-saas --skill kotlin-coroutines-flows-freedom909

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing asynchronous Kotlin code without structured patterns leads to leaked coroutines, uncancellable work, and untestable reactive streams. This Skill provides proven patterns for coroutines and Flow so async code stays scoped, cancellable, and testable. ## Core Features & Use Cases - Structured Concurrency: Replace GlobalScope with viewModelScope, coroutineScope, and supervisorScope for lifecycle-aware parallel work. - Flow Patterns: Build StateFlow UI state, combine multiple flows, debounce search input, retry with exponential backoff, and emit one-time events via SharedFlow. - Testing Support: Test StateFlow with Turbine, control time with runTest and TestDispatcher, and fake repositories with MutableStateFlow. - Use Case: When building an Android dashboard screen, use this Skill to load items, stats, and profile in parallel with async/await, expose them as a combined StateFlow, and verify emissions in unit tests. ## Quick Start Use the kotlin-coroutines-flows skill to refactor my ViewModel to load dashboard data in parallel and expose it as a StateFlow.

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 await each result. This keeps all tasks structured under one scope so a failure cancels siblings and no coroutine leaks.

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 5-second timeout keeps the upstream active across configuration changes without restarting collection.

StateFlow vs SharedFlow: which should I use for UI events?▼

Use StateFlow for persistent UI state that always has a current value, and SharedFlow for one-time events like snackbars or navigation. SharedFlow avoids re-delivering stale events after configuration changes.

Does Dispatchers.IO work in Kotlin Multiplatform?▼

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

How do I test Kotlin Flows with Turbine?▼

Wrap the Flow or StateFlow in flow.test inside a runTest block, then assert each emission with awaitItem. Turbine fails the test if unconsumed events remain, catching unexpected emissions.

Why should I avoid GlobalScope in Kotlin coroutines?▼

GlobalScope launches coroutines with no parent, so they are never cancelled with a lifecycle and can leak work. Use viewModelScope, lifecycleScope, or an explicit coroutineScope for structured cancellation.