Daniele Segato
12/21/2020, 3:10 PMMutableStateFlow
for the first time, but it is not doing what I expect
private val state = MutableStateFlow<MyState>(INITIAL_STATE)
suspend fun refresh(): MyState {
val newState = service.refresState()
this.state.value = newState
return newState
}
fun observeState(): Flow<MyState> {
return state
.transform { s ->
if (s !== INITIAL_STATE) {
emit(s)
} else {
refresh() // expecting this to automatically send a new state to the flow
}
}
}
I was expecing the refresh()
to cause a new state to be emitted, but it didn't.
Can someone guide me in the right direction?
thanks.Joost Klitsie
12/21/2020, 3:31 PMDaniele Segato
12/21/2020, 3:32 PM