Flow: the Basics
KOTLIN › Concurrency
What a Kotlin Flow actually is: an async stream of values over time, the producer/collector model, emit and collect, cold execution, and why it beats callbacks.
This is the ground floor of everything reactive on Android. Before operators, StateFlow, or combining streams, you need the core picture: a Flow is a stream of values that arrive over time, produced with flow { emit(...) } and consumed with collect { } inside a coroutine. It does nothing until collected, and it's cold, each collector gets its own run. Get comfortable here and the Flow & Operators lesson, which assumes all of this, will actually click.
What this covers
- A suspend function returns one value once; a Flow is a stream of many values arriving over time
- flow { } is the producer and emit() sends values one at a time; collect { } is the consumer whose lambda runs per value
- A Flow does nothing until a terminal operator like collect() runs it, it's just a description until then
- emit and collect are sequential and suspending, so you can call suspend functions (network, delay) inside a flow, no callbacks
- collect is a suspend function, so it must run inside a coroutine (launch, viewModelScope, another suspend fun)
- A cold flow re-runs its producer independently for every collector; nothing is shared until you go hot (shareIn/stateIn)
Study this topic
- Flow: the Basics explained: the guided lesson
- 10 practice quiz questions
- 8 revision flashcards
- Flow: the Basics interview questions and answers