kotlin-coroutines-flows

Standardize Kotlin Coroutines and Flow usage for structured concurrency and reactive state.

1|Updated Mar 3, 2026
One-click install
npx skills add https://github.com/samymity/bridge-ventures-backend --skill kotlin-coroutines-flows-samymity
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-coroutines-flows
Source: https://github.com/samymity/bridge-ventures-backend/tree/main/.claude/skills/kotlin-coroutines-flows
Command: npx skills add https://github.com/samymity/bridge-ventures-backend --skill kotlin-coroutines-flows-samymity

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Kotlin coroutine and Flow code often becomes fragile, hard to test, and prone to leaks or cancellation bugs when scopes, error handling, and reactive operators are used inconsistently.

Core Features & Use Cases

  • Structured Concurrency: Uses scope hierarchies, coroutineScope, and supervisorScope to run concurrent work safely and deterministically without GlobalScope.
  • Flow Architecture Patterns: Shows practical approaches for cold flows, StateFlow for UI state, SharedFlow for one-time events, and combining multiple flows into a single state model.
  • Correct Operator Usage & Reliability: Covers common operators like debounce, distinctUntilChanged, flatMapLatest, plus retry strategies with exponential backoff.
  • Testing & Cancellation Safety: Demonstrates coroutine/Flow testing with runTest, turbine-style assertions, fakes with MutableStateFlow, and cooperative cancellation patterns.

Quick Start

Tell the AI to generate a coroutine + Flow-based ViewModel that loads multiple resources in parallel, exposes StateFlow UI state, emits SharedFlow one-time navigation/snackbar effects, and includes a test that verifies the initial loading and the final populated state.

Frequently Asked Questions about kotlin-coroutines-flows

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

FAQPage Schema
How do I prevent scope leaks and cancellation bugs in Kotlin coroutines?

Prevent coroutine scope leaks by applying structured concurrency patterns that enforce scope hierarchies using `coroutineScope` and `supervisorScope`, ensuring safe concurrent work without relying on `GlobalScope`.

When should I use StateFlow vs SharedFlow for Kotlin UI state and events?

Use `StateFlow` for exposing UI state and `SharedFlow` for emitting one-time events like navigation or snackbar effects, combining multiple flows into a single reactive state model for consistent UI updates.

How do I test Kotlin Flow and coroutine timing deterministically?

Test Kotlin Flow and coroutines deterministically by using `runTest` with test dispatchers, turbine-style assertions, and `MutableStateFlow` fakes to verify loading states and final populated data without real delays.

What's the best way to handle errors and retries in Kotlin Flow operator chains?

Handle errors and retries in Kotlin Flow operator chains by applying resilient operator combinations with `debounce`, `distinctUntilChanged`, `flatMapLatest`, and retry strategies using exponential backoff for reliable reactive streams.

Does this structured concurrency approach work for Kotlin Multiplatform codebases?

Yes, the structured concurrency and Flow architecture patterns apply to both Android and Kotlin Multiplatform codebases, standardizing reactive state management and scoped launches across different platforms.