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
When a TimeoutCancelationException occurs inside a flow it gets thrown and can be caught in the catch block. But if it is thrown in a flow that is attached with a flatMap the exception is ignored/swallowed.
Provide a Reproducer
The code at the bottom of this section running in https://play.kotlinlang.org/ using version kotlin 1.8.20 emits the following
This should never execute
Found error java.lang.RuntimeException
Found error kotlinx.coroutines.TimeoutCancellationException: Timed out immediately
but it should emit the following:
Found error kotlinx.coroutines.TimeoutCancellationException: Timed out immediately
Found error java.lang.RuntimeException
Found error kotlinx.coroutines.TimeoutCancellationException: Timed out immediately
importkotlinx.coroutines.flow.*importkotlinx.coroutines.*
@kotlinx.coroutines.ExperimentalCoroutinesApifunmain() = runBlocking {
runTest {
withTimeout(0L) {
// Do nothing this will not execute
}
}
runTest {
throwRuntimeException()
}
flow<Boolean> {
emit(true)
//throw RuntimeException()
withTimeout(0L) {
// Do nothing this will not execute
}
}
.onCompletion {
if(it ==null) println("This should never execute")
}
.catch { println("Found error $it") }
.collect()
}
suspendfunrunTest(block:suspendFlowCollector<Boolean>.() ->Unit) = flow {
emit(true)
}.flatMapLatest {
flow<Boolean> {
block()
}
}.onCompletion {
if(it ==null) println("This should never execute")
}
.catch { println("Found error $it") }
.collect()
The text was updated successfully, but these errors were encountered:
Describe the bug
When a TimeoutCancelationException occurs inside a flow it gets thrown and can be caught in the
catch
block. But if it is thrown in a flow that is attached with aflatMap
the exception is ignored/swallowed.Provide a Reproducer
The code at the bottom of this section running in https://play.kotlinlang.org/ using version kotlin 1.8.20 emits the following
but it should emit the following:
The text was updated successfully, but these errors were encountered: