hfhbd
10/13/2022, 2:50 PMhfhbd
10/13/2022, 2:51 PM@Test
fun a() = runTest(dispatchTimeoutMs = 1.seconds.inWholeMilliseconds) {
val listener = flow {
var i = 0
while (currentCoroutineContext().isActive) {
emit(i)
i++
yield()
println("FLOW $i")
}
}.shareIn(this, SharingStarted.WhileSubscribed(replayExpiration = ZERO))
launch {
listener.collect {
if (it == 1) {
println("COLLECT $it")
cancel()
}
}
}
}
I would expect listener
will be canceled because I use WhileSubscribed
and the only subscriber is canceledZach Klippenstein (he/him) [MOD]
10/13/2022, 3:02 PMhfhbd
10/13/2022, 3:14 PMkotlinx.coroutines.test.UncompletedCoroutinesError: After waiting for 1000 ms, the test coroutine is not completing, there were active child jobs: ["coroutine#2":StandaloneCoroutine{Active}@34f6515b]
. And I don't know, which is the active child job.hfhbd
10/13/2022, 3:23 PMStateFlow
this coroutine will never finish and is always active.