Skip to content

Commit 5801a5a

Browse files
committed
Getting rid of internal flow exception. It's not needed.
1 parent cd54fe0 commit 5801a5a

File tree

1 file changed

+11
-17
lines changed
  • kotlinx-coroutines-core/common/src/flow/operators

1 file changed

+11
-17
lines changed

kotlinx-coroutines-core/common/src/flow/operators/Delay.kt

+11-17
Original file line numberDiff line numberDiff line change
@@ -464,23 +464,20 @@ private fun <T> Flow<T>.timeoutInternal(
464464
}
465465
}
466466

467-
try {
468-
// Await for values from our producer now
469-
whileSelect {
470-
values.onReceiveOrNull { value ->
471-
if (value !== DONE) {
472-
if (value === TIMEOUT) {
473-
throw InternalFlowTimeoutException()
474-
}
475-
downStream.emit(NULL.unbox(value))
476-
return@onReceiveOrNull true
467+
// Await for values from our producer now
468+
whileSelect {
469+
values.onReceiveOrNull { value ->
470+
if (value !== DONE) {
471+
if (value === TIMEOUT) {
472+
action(downStream)
473+
values.cancel(ChildCancelledException())
474+
return@onReceiveOrNull false // Just end the loop here. Nothing more to be done.
477475
}
478-
return@onReceiveOrNull false // We got the DONE signal, so exit the while loop
476+
downStream.emit(NULL.unbox(value))
477+
return@onReceiveOrNull true
479478
}
479+
return@onReceiveOrNull false // We got the DONE signal, so exit the while loop
480480
}
481-
} catch (e: InternalFlowTimeoutException) {
482-
action(downStream)
483-
values.cancel(ChildCancelledException())
484481
}
485482
}
486483

@@ -501,6 +498,3 @@ internal fun FlowTimeoutException(time: Long) : FlowTimeoutException = FlowTimeo
501498

502499
// Special timeout flag
503500
private val TIMEOUT = Symbol("TIMEOUT")
504-
505-
// Special indicator exception
506-
private class InternalFlowTimeoutException : Exception("Internal flow timeout exception")

0 commit comments

Comments
 (0)