Shashank
09/13/2020, 1:54 PMStateFlow
by asserting the list of values received by it.
data class State(val isLoading: Boolean, val name: String?)
fun main() {
val mutableStateFlow = MutableStateFlow(State(false, null))
val stateFlow = mutableStateFlow as StateFlow<State>
val scope1 = CoroutineScope(Job())
val scope2 = CoroutineScope(Job())
scope1.launch {
delay(1000)
mutableStateFlow.value = State(true, null)
mutableStateFlow.value = State(false, "name")
}
scope2.launch {
stateFlow.collect {
println("value = $it")
}
}
Thread.sleep(2000)
}
Here is my code. Instead of getting State(true, null)
as the second value, I only receive the initial value and the last value (State(false, name)
)