Skip to content

Commit 505ba3c

Browse files
committed
avoid ChildCancelledException Kotlin/kotlinx.coroutines#2550
1 parent 6d339de commit 505ba3c

File tree

1 file changed

+2
-4
lines changed
  • firebase-common/src/commonMain/kotlin/dev/gitlive/firebase

1 file changed

+2
-4
lines changed

firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/extensions.kt

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import kotlinx.coroutines.channels.SendChannel
66

77
//workaround for https://github.com/Kotlin/kotlinx.coroutines/issues/974
88
@ExperimentalCoroutinesApi
9-
fun <E> SendChannel<E>.safeOffer(element: E) = try {
10-
!isClosedForSend && offer(element)
11-
} catch (e : ClosedSendChannelException) {
12-
false
9+
fun <E> SendChannel<E>.safeOffer(element: E): Boolean {
10+
return runCatching { !isClosedForSend && offer(element) }.getOrDefault(false)
1311
}

0 commit comments

Comments
 (0)