
Kotlin Coroutines Flows
Apply Kotlin coroutines, Flow operators, StateFlow, structured concurrency, and coroutine tests in Android and KMP codebases.
Overview
Kotlin Coroutines Flows is an agent skill most often used in Build (also Ship testing, Operate iterate) that encodes structured concurrency and Flow patterns for Android and KMP.
Install
npx skills add https://github.com/affaan-m/everything-claude-code --skill kotlin-coroutines-flowsWhat is this skill?
- Structured concurrency: viewModelScope, LaunchedEffect—explicit anti-pattern for GlobalScope
- Parallel decomposition with coroutineScope + async for dashboard-style loads
- Flow, StateFlow, SharedFlow operators, debounce, retry, and error handling guidance
- Android and Kotlin Multiplatform (KMP) applicability called out in description
- Activation triggers for testing coroutines and Flows alongside production async code
Adoption & trust: 4.5k installs on skills.sh; 210k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
Your agent keeps suggesting GlobalScope, blocking calls, or untested Flow pipelines that break lifecycle cancellation on Android and KMP screens.
Who is it for?
Indie Android/KMP developers who want consistent async, Flow, and testing guidance while implementing features or fixing concurrency bugs.
Skip if: Greenfield backend-only Kotlin services with no mobile UI, or teams that need Jetpack Compose layout/theming skills without async depth.
When should I use this skill?
Writing async code with Kotlin coroutines; using Flow, StateFlow, or SharedFlow; parallel loading, debounce, retry; testing coroutines and Flows; managing scopes and cancellation.
What do I get? / Deliverables
You get scoped coroutine launches, parallel async decomposition, and Flow/StateFlow patterns aligned with testable Android and KMP architecture.
- Idiomatic coroutine and Flow code snippets
- Structured concurrency and testing-aligned async patterns
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Primary shelf is Build because async UI and data layers are authored during implementation; patterns also support ship-time testing and operate-time reliability fixes. Frontend subphase fits Compose/ViewModel-scoped async and Flow-driven UI state; patterns span repositories used from mobile presentation layers.
Where it fits
Implement a Compose screen that loads items, stats, and profile in parallel inside coroutineScope before rendering StateFlow-driven UI.
Add Turbine-style or coroutines test rules to verify Flow emissions and cancellation when the ViewModel clears.
Replace fire-and-forget launches causing leaks with scoped jobs and debounced search Flow after a production ANR report.
How it compares
Procedural Kotlin concurrency reference—not a project scaffold skill or a CI-only test runner integration.
Common Questions / FAQ
Who is kotlin-coroutines-flows for?
Solo builders and small teams writing Android or KMP apps who want agent output to follow structured concurrency and Flow best practices.
When should I use kotlin-coroutines-flows?
In Build when implementing ViewModel/Compose async, parallel repository loads, or StateFlow UI state; in Ship when writing coroutine and Flow tests; in Operate when refactoring cancellation or retry behavior in production hot paths.
Is kotlin-coroutines-flows safe to install?
It is documentation-style patterns without mandatory shell/network gates—still review the Security Audits panel on this Prism page before adding third-party skills to your agent.
SKILL.md
READMESKILL.md - Kotlin Coroutines Flows
# Kotlin Coroutines & Flows Patterns for structured concurrency, Flow-based reactive streams, and coroutine testing in Android and Kotlin Multiplatform projects. ## When to Activate - Writing async code with Kotlin coroutines - Using Flow, StateFlow, or SharedFlow for reactive data - Handling concurrent operations (parallel loading, debounce, retry) - Testing coroutines and Flows - Managing coroutine scopes and cancellation ## Structured Concurrency ### Scope Hierarchy ``` Application └── viewModelScope (ViewModel) └── coroutineScope { } (structured child) ├── async { } (concurrent task) └── async { } (concurrent task) ``` Always use structured concurrency — never `GlobalScope`: ```kotlin // BAD GlobalScope.launch { fetchData() } // GOOD — scoped to ViewModel lifecycle viewModelScope.launch { fetchData() } // GOOD — scoped to composable lifecycle LaunchedEffect(key) { fetchData() } ``` ### Parallel Decomposition Use `coroutineScope` + `async` for parallel work: ```kotlin suspend fun loadDashboard(): Dashboard = coroutineScope { val items = async { itemRepository.getRecent() } val stats = async { statsRepository.getToday() } val profile = async { userRepository.getCurrent() } Dashboard( items = items.await(), stats = stats.await(), profile = profile.await() ) } ``` ### SupervisorScope Use `supervisorScope` when child failures should not cancel siblings: ```kotlin suspend fun syncAll() = supervisorScope { launch { syncItems() } // failure here won't cancel syncStats launch { syncStats() } launch { syncSettings() } } ``` ## Flow Patterns ### Cold Flow — One-Shot to Stream Conversion ```kotlin fun observeItems(): Flow<List<Item>> = flow { // Re-emits whenever the database changes itemDao.observeAll() .map { entities -> entities.map { it.toDomain() } } .collect { emit(it) } } ``` ### StateFlow for UI State ```kotlin class DashboardViewModel( observeProgress: ObserveUserProgressUseCase ) : ViewModel() { val progress: StateFlow<UserProgress> = observeProgress() .stateIn( scope = viewModelScope, started = SharingStarted.WhileSubscribed(5_000), initialValue = UserProgress.EMPTY ) } ``` `WhileSubscribed(5_000)` keeps the upstream active for 5 seconds after the last subscriber leaves — survives configuration changes without restarting. ### Combining Multiple Flows ```kotlin val uiState: StateFlow<HomeState> = combine( itemRepository.observeItems(), settingsRepository.observeTheme(), userRepository.observeProfile() ) { items, theme, profile -> HomeState(items = items, theme = theme, profile = profile) }.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), HomeState()) ``` ### Flow Operators ```kotlin // Debounce search input searchQuery .debounce(300) .distinctUntilChanged() .flatMapLatest { query -> repository.search(query) } .catch { emit(emptyList()) } .collect { results -> _state.update { it.copy(results = results) } } // Retry with exponential backoff fun fetchWithRetry(): Flow<Data> = flow { emit(api.fetch()) } .retryWhen { cause, attempt -> if (cause is IOException && attempt < 3) { delay(1000L * (1 shl attempt.toInt())) true } else { false } } ``` ### SharedFlow for One-Time Events ```kotlin class ItemListViewModel : ViewModel() { private val _effects = MutableSharedFlow<Effect>() val effects: SharedFlow<Effect> = _effects.asSharedFlow() sealed interface Effect { data class ShowSnackbar(val message: String) : Effect data class NavigateTo(val route: String) : Effect } private