dave08
05/10/2020, 6:57 AMStateFlow
can't be collected by multiple collectors (maybe it just fans-out?)?
val state = MutableStateFlow(1)
val scope = CoroutineScope(<http://Dispatchers.IO|Dispatchers.IO>)
runBlocking {
println("start")
state.onEach { println("$it-1") }.launchIn(scope)
println("here")
state.value = 2
state.onEach { println("$it-2") }.launchIn(scope)
state.value = 3
println("finished")
// scope.coroutineContext[Job]!!.join()
}
results in:
start
here
2-1
finished
3-2
(If I uncomment the last line, it hangs the scratch... so maybe I'm just loosing the emissions?)