From 505ba3c986013ab240e046f067233137afccfd9d Mon Sep 17 00:00:00 2001 From: nbransby Date: Fri, 5 Mar 2021 15:35:10 +0000 Subject: [PATCH] avoid ChildCancelledException https://github.com/Kotlin/kotlinx.coroutines/issues/2550 --- .../commonMain/kotlin/dev/gitlive/firebase/extensions.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/extensions.kt b/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/extensions.kt index 478dc58ec..18498cbd7 100644 --- a/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/extensions.kt +++ b/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/extensions.kt @@ -6,8 +6,6 @@ import kotlinx.coroutines.channels.SendChannel //workaround for https://github.com/Kotlin/kotlinx.coroutines/issues/974 @ExperimentalCoroutinesApi -fun SendChannel.safeOffer(element: E) = try { - !isClosedForSend && offer(element) -} catch (e : ClosedSendChannelException) { - false +fun SendChannel.safeOffer(element: E): Boolean { + return runCatching { !isClosedForSend && offer(element) }.getOrDefault(false) } \ No newline at end of file