dimsuz
06/21/2020, 5:31 PMrunBlocking {
val state = MutableStateFlow(0)
launch { state.value = 1 }
launch { state.value = 2 }
launch { state.value = 3 }
state.collect {
println("received $it")
}
}
prints
received 0
received 3
Is there a way to receive all values and also have the property of StateFlow
that new collections will receive the last value?Adam Powell
06/21/2020, 5:40 PMdimsuz
06/21/2020, 5:47 PMenum State { Working, Done }
class AuthFeature {
fun login() {
state.value = Working
performRequest()
state.value = Done
}
fun loginState(): Flow<State>
}
And my UI observes the loginState()
if performRequest() is fast, (cached), state is lost. I tried added launch
or yield
, it doesn't help.dimsuz
06/21/2020, 5:51 PMSharedFlow
which doesn't conflate values and waits for consumers to process them, so I guess I'll have to wait for it.Adam Powell
06/21/2020, 5:51 PMdimsuz
06/21/2020, 5:53 PMdimsuz
06/21/2020, 5:54 PMZach Klippenstein (he/him) [MOD]
06/21/2020, 5:59 PMError
state isn’t really a state then, it’s an event.Adam Powell
06/21/2020, 6:01 PMdimsuz
06/21/2020, 7:48 PMloginState()
is my props, I want to render it.Zach Klippenstein (he/him) [MOD]
06/21/2020, 7:59 PMAdam Powell
06/21/2020, 8:01 PMAdam Powell
06/21/2020, 8:03 PMdimsuz
06/21/2020, 8:17 PMdimsuz
06/21/2020, 8:19 PMairbnb/MvRx
, they had to invent their own abstraction to make sure all state emissions are delivered: CoroutineStateStoreAdam Powell
06/21/2020, 8:30 PMAdam Powell
06/21/2020, 8:32 PMdimsuz
06/21/2020, 8:52 PM