Daniele Segato
09/10/2021, 2:44 PMval sourceA = MutableStateFlow<A>(null)
val sourceB = MutableStateFlow<B>(null)
val dataFromA = sourceA.map { it.x }.distinctUntilChanged()
val dataFromB = sourceB.map { it.y }.distinctUntilChanged()
val updateProcedure =
dataFromA
.combine(dataFromB) { x, y -> x to y }
.distinctUntilChanged()
.onEach { (x, y) ->
otherMutableStateFlow.update { /*...*/ }
}
.launcIn(viewModelScope)
now if I input changing data in sourceA it is completely ignored after the 1st one: my onEach
run only once.
if I remove the combine and just get data from A + hardcode y to something it gets called every time.
I've used combine SO MANY times and this is the first time something like this is happening to me.
Does anyone have ANY idea of what could be going on here?.flowOn(defaultDispatcher)
where I injected the defaultDispatcher
to be a TestCoroutineDispatcher()
from my test and apparently when you use .combine()
with a test dispatcher you need to call advanceUntilIdle()
on the dispatcher or it will be stuck there forever