kotlin-flow-state-event-modeling

Model Kotlin Flow state and event APIs to prevent lost emissions and stale reads.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/soygabimoreno/Los-ANDROIDES --skill kotlin-flow-state-event-modeling
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-flow-state-event-modeling
Source: https://github.com/soygabimoreno/Los-ANDROIDES/tree/main/.agents/skills/kotlin-flow-state-event-modeling
Command: npx skills add https://github.com/soygabimoreno/Los-ANDROIDES --skill kotlin-flow-state-event-modeling

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It solves the common Kotlin Flow mistakes that cause lost one-shot events, stale UI state, and unsafe state initialization that leaks placeholder/sentinel domain values into the app.

Core Features & Use Cases

  • Correctly model UI state vs one-shot events: Use StateFlow for always-available state and Buffered Channel/receiveAsFlow for exactly-once navigation/snackbar events.
  • Avoid concurrency bugs in MutableStateFlow: Prefer MutableStateFlow.update to prevent lost updates from read-modify-write patterns.
  • Prevent inefficient or incorrect sharing: Ensure stateIn is defined once (as a val) and choose SharingStarted.WhileSubscribed only when stale cached .value is acceptable.
  • Keep synchronous access when deriving state: Don’t rely on .map over StateFlow when consumers need synchronous .value; terminate with .stateIn.

Quick Start

Use the kotlin-flow-state-event-modeling skill to review a ViewModel’s StateFlow/SharedFlow/Channel design and identify where events may drop, where .value may go stale, or where update/stateIn decisions could cause concurrency or performance issues.

Frequently Asked Questions about kotlin-flow-state-event-modeling

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

FAQPage Schema
How do I prevent lost emissions with Kotlin SharedFlow in my ViewModel?

To prevent lost emissions in Kotlin SharedFlow, use a buffered Channel with receiveAsFlow for exactly-once events like navigation or snackbars, reserving StateFlow for always-available UI state.

Why does my MutableStateFlow lose updates during concurrent read-modify-write operations?

MutableStateFlow loses updates during concurrent read-modify-write operations due to race conditions; you must apply atomic update transforms using MutableStateFlow.update to prevent lost state changes.

What is the best way to model one-shot events versus state in Kotlin Flow?

The best way to model Kotlin Flow state and events is using StateFlow for always-available domain state and Buffered Channel.receiveAsFlow for exactly-once UI events like snackbars or navigation.

When should I use stateIn with SharingStarted.WhileSubscribed in Kotlin Flow?

Use stateIn with SharingStarted.WhileSubscribed in Kotlin Flow only when stale cached .value is acceptable, ensuring the stateIn sharing lifetime is defined once as a val to prevent inefficient sharing.

How do I keep synchronous access to .value when deriving state from a StateFlow?

To keep synchronous access to .value when deriving state from a StateFlow, do not rely on .map; terminate the flow chain with .stateIn so consumers can safely read synchronous values.