I'm having a curious issue when dealing with flatMapLatest and emptyFlow as well as firstOrNull.
Scenario A:
val dataFlow: Flow<Boolean> = emptyFlow()
launch {
val data = dataFlow.firstOrNull() // returns data = null
}
Scenario B:
val rootFlow: MutableStateFlow<Boolean?> = MutableStateFlow(null)
val dataFlow: Flow<Boolean> = rootFlow.flatMapLatest {
emptyFlow()
}
launch {
val data = dataFlow.firstOrNull() // blocks and does not return any value
}
So my question would be, why does firstOrNull not return any value in Scenario B.
I'm seeing that flatMapLatest is being called with the initial null value of the mutable state flow.