Tgo1014
03/31/2023, 8:41 AMfalse if the line before it prints 1 ?
val flow = MutableStateFlow(2)
val flowB: StateFlow<Boolean> = flow
.map { it == 1 }
.stateIn(GlobalScope, SharingStarted.Eagerly, false)
println(flow.value) // 2
flow.value = 1
println(flow.value) // 1
println(flowB.value) // falsefranztesca
03/31/2023, 9:12 AMflow , there is some time before flowB picks collects the value from flow, maps it and emits it.
Your println statements are executed in that time, after 1 is emitted by flow but before 1 is collected by flowB.
You can run flowB on an Unconfined dispatcher to make it process the value as soon as it is emitted by flow.
.stateIn(GlobalScope + Dispatchers.Unconfined