Eury Perez
04/24/2023, 12:54 PMval values = mutableListOf<Int>()
val sharedFlow = MutableSharedFlow<Int>()
sharedFlow.emit(0)
val job = launch { // <------
stateFlow.collect {
values.add(it)
}
}
runCurrent()
sharedFlow.emit(1)
runCurrent()
sharedFlow.emit(2)
runCurrent()
sharedFlow.emit(3)
runCurrent()
job.cancel()
assertEquals(listOf(0, 1, 2, 3), values)
A similar test passes with stateflowstojan
04/24/2023, 1:02 PMIf there are no subscribers, the buffer is not used. Instead, the most recently emitted value is simply stored into the replay cache if one was configured, displacing the older elements there, or dropped if no replay cache was configured.emphasis mine
Eury Perez
04/24/2023, 1:18 PM