You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I use the replay parameter in the MutableSharedFlow function, then at some point in time the flow stops emitting values. The problem is reproducible if subscribers process values with different delays. But if the delays are equal, then it works correctly.
Сode:
private val state = MutableSharedFlow<Int>(1)
fun main() {
val delay1: Long = 100
val delay2: Long = 400
state
.onEach {
delay(delay1)
println("item1 = $it")
}.launchIn(GlobalScope)
state
.onEach {
delay(delay2)
println("item2 = $it")
}.launchIn(GlobalScope)
val job = GlobalScope.launch(Dispatchers.IO) {
delay(1.seconds)
for (i in 0..5) {
state.emit(i)
println("emit = $i")
delay(100)
}
}
runBlocking {
delay(10.seconds)
println("Job = $job")
}
}
Problematic scenario:
* Emitter suspends because there is a slow subscriber
* Fast subscriber collects all the values and suspend
* Slow subscriber resumes, collects value, causes emitter to be resume
* Fast subscribers must be resumed in this case, too
Fixes#2320
If I use the
replay
parameter in theMutableSharedFlow
function, then at some point in time the flow stops emitting values. The problem is reproducible if subscribers process values with different delays. But if the delays are equal, then it works correctly.Сode:
Result:
The text was updated successfully, but these errors were encountered: