util: correctly throw channel errors

Wasn't being properly handled before, leading to weird behavior.
This commit is contained in:
Alexander Capehart 2024-01-01 12:01:13 -07:00
parent ed519eeccc
commit 77f0bbe614
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47

View file

@ -186,7 +186,7 @@ suspend fun <E> ReceiveChannel<E>.forEachWithTimeout(
var subsequent = false
val handler: suspend () -> Unit = {
val value = receiveCatching()
if (value.isClosed) {
if (value.isClosed && value.exceptionOrNull() == null) {
exhausted = true
} else {
action(value.getOrThrow())