kotlin-coroutines-flows

Apply structured concurrency and cancellation-safe patterns to Kotlin coroutines and Flows.

Updated Sep 13, 2025
One-click install
npx skills add https://github.com/llmh333/employee_management_spring --skill kotlin-coroutines-flows-llmh333
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-coroutines-flows
Source: https://github.com/llmh333/employee_management_spring/tree/main/.gemini/skills/kotlin-coroutines-flows
Command: npx skills add https://github.com/llmh333/employee_management_spring --skill kotlin-coroutines-flows-llmh333

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you write reliable, maintainable asynchronous code by preventing common coroutine and Flow mistakes that cause leaks, race conditions, and flaky UI behavior.

Core Features & Use Cases

  • Structured concurrency patterns: Use scoped launches (e.g., viewModelScope), parallel decomposition with coroutineScope + async, and supervisorScope for sibling failure isolation.
  • Flow architecture for UI and events: Model continuous UI state with StateFlow/SharedFlow and compose multiple streams with combine and operator chains like debounce/flatMapLatest.
  • Cancellation-aware execution and testing: Ensure cooperative cancellation with ensureActive, always-run cleanup with try/finally, and verify behavior using runTest with Turbine and TestDispatcher.

Quick Start

Ask the AI to generate a ViewModel design that uses StateFlow for UI state and SharedFlow for one-time navigation events, with proper structured concurrency and coroutine testing.

Frequently Asked Questions about kotlin-coroutines-flows

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

FAQPage Schema
How do I model UI state with StateFlow and handle one-time events with SharedFlow in Kotlin?

Model continuous UI state with StateFlow and emit one-time navigation events using SharedFlow. This Skill designs ViewModels with proper structured concurrency, ensuring reactive streams compose safely without leaking or racing.

What's the best way to prevent memory leaks when running parallel coroutine tasks in Kotlin Multiplatform?

Prevent coroutine memory leaks by applying structured concurrency using scoped launches and coroutineScope with async. This Skill enforces scope discipline, avoiding GlobalScope to ensure parallel workloads cancel properly on scope completion.

How does structured concurrency improve cancellation safety in Kotlin Flow pipelines?

Structured concurrency improves cancellation safety by requiring cooperative checks like ensureActive and try/finally cleanup blocks. This Skill builds resilient Flow operator pipelines that handle errors and cancellation reliably across dispatchers.

How do I test Kotlin coroutines and Flow streams without flaky behavior?

Test coroutines and Flow streams deterministically using runTest with Turbine and TestDispatcher. This Skill provides patterns to verify StateFlow emissions, cancellation behavior, and operator pipeline logic without relying on real time delays.

Can I use Kotlin coroutines and Flow for asynchronous workloads across Android and Kotlin Multiplatform?

Yes, coroutines and Flow support asynchronous workloads across Android and Kotlin Multiplatform. This Skill guides dispatcher selection across platforms to ensure safe parallel data loading and UI state modeling in shared codebases.

Why does my SharedFlow emit duplicate events or miss collection in Android ViewModels?

SharedFlow mishandles events when replay configurations or collector lifecycles are incorrect. This Skill applies reactive stream design patterns, configuring SharedFlow to emit one-time UI effects safely without duplication or loss.