kotlin-coroutines-flows

Implement structured concurrency and Flow patterns for Kotlin async code.

2|Updated Mar 12, 2026
One-click install
npx skills add https://github.com/sayasaya8039/ZWG_Terminal --skill kotlin-coroutines-flows-sayasaya8039
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-coroutines-flows
Source: https://github.com/sayasaya8039/ZWG_Terminal/tree/main/.claude/skills/kotlin-coroutines-flows
Command: npx skills add https://github.com/sayasaya8039/ZWG_Terminal --skill kotlin-coroutines-flows-sayasaya8039

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing maintainable, leak-free asynchronous code in Kotlin for Android and Kotlin Multiplatform projects is challenging, with common pitfalls like unstructured coroutine scopes, unhandled Flow errors, and flaky async tests wasting development time.

Core Features & Use Cases

  • Structured Concurrency Patterns: Proper scope hierarchy, parallel decomposition with async/await, and supervisorScope for isolated child failures, eliminating memory leaks from GlobalScope usage.
  • Reactive Flow Operators: Pre-built patterns for StateFlow UI state management, combining multiple data streams, debouncing user input, retrying failed requests with exponential backoff, and handling one-time events with SharedFlow.
  • Coroutine Testing Utilities: Ready-to-use examples for testing StateFlow with Turbine, faking Flow repositories, and using TestDispatchers for reliable async test suites.
  • Use Case Example: Build a multi-source dashboard that loads user items, stats, and profile data in parallel, with automatic retry on network failure and UI state that survives configuration changes.

Quick Start

Use the kotlin-coroutines-flows skill to implement a debounced search screen that retries failed API requests and exposes loading, error, and results states via StateFlow for your Android composable.

Frequently Asked Questions about kotlin-coroutines-flows

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

FAQPage Schema
How do I manage UI state with StateFlow in Kotlin Android without leaking coroutines?

Manage UI state with StateFlow by applying structured concurrency patterns that bind coroutine scopes to the Android lifecycle. This eliminates memory leaks by ensuring scopes are properly cancelled when views are destroyed.

What is the best way to handle debounced user input and retry failed network requests in Kotlin?

The best way to handle debounced input and network retries is using Flow reactive stream operators. You can implement exponential backoff for failed requests while debouncing rapid user input events to prevent unnecessary API calls.

How do I test Kotlin coroutines and StateFlow reliably without flaky async test suites?

Test Kotlin coroutines and StateFlow reliably by using TestDispatchers and the Turbine library. Faking Flow repositories with TestDispatchers replaces real dispatcher delays, ensuring deterministic and stable async test execution.

Does this Kotlin coroutines pattern work for Kotlin Multiplatform projects?

Yes, these structured concurrency and Flow reactive stream patterns explicitly support Kotlin Multiplatform projects. The architecture handles platform-appropriate dispatcher selection for both Android and shared KMP codebases.

Why should I avoid GlobalScope when writing asynchronous Kotlin code?

You should avoid GlobalScope because it creates unstructured concurrency that outlives the calling component, causing memory leaks. Using properly scoped coroutines ensures cancellation and error handling are managed within the correct lifecycle.