What problem does it solve?
It reduces bugs and lifecycle-related leaks caused by incorrect coroutine usage and Flow handling by providing clear patterns for structured concurrency, cancellation, dispatcher selection, and reactive UI state management.
Core Features & Use Cases
- Structured Concurrency: guidance for scoping coroutines to ViewModel, composables, and application lifecycles to avoid leaks.
- Flow Patterns: techniques for StateFlow, SharedFlow, cold flows, combining multiple flows, and operator usage such as debounce, distinctUntilChanged, flatMapLatest, and retry strategies.
- Dispatchers & Cancellation: recommendations for choosing Dispatchers across Android and KMP, cooperative cancellation, and cleanup with try/finally.
- Testing Strategies: examples for using TestDispatcher, runTest, and Turbine to assert StateFlow and Flow behavior.
- Use Case: refactor a dashboard ViewModel to load items and stats in parallel with proper error isolation, expose a StateFlow UI model, and emit one-time navigation/snackbar events with SharedFlow.
Quick Start
Use the kotlin-coroutines-flows skill to review and refactor a ViewModel to use coroutineScope with async for parallel loading, StateFlow for UI state, and TestDispatcher-based tests.