Hey everyone! I am trying to test my `StateFlow` b...
# announcements
s
Hey everyone! I am trying to test my
StateFlow
by asserting the list of values received by it.
Copy code
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)
)