From 2d662f91b3e2bde256ff57cec4ae696ee62380d5 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 29 Mar 2021 17:57:36 +0600 Subject: [PATCH] updates in coroutines --- CHANGELOG.md | 4 ++++ .../coroutines/FlowSubscription.kt | 24 ++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec99ece5c80..2f9823c93ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ * `Versions`: * `Kotlin`: `1.4.31` -> `1.4.32` * Add subproject `repos.cache` +* `Coroutines`: + * Rewrite `subscribeSafelyWithoutExceptions` + * Now `subscribeSafelyWithoutExceptions` will use default handler instead of skipping + * New extension `subscribeSafelySkippingExceptions` ## 0.4.30 diff --git a/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/FlowSubscription.kt b/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/FlowSubscription.kt index 26588ac166c..76546375293 100644 --- a/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/FlowSubscription.kt +++ b/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/FlowSubscription.kt @@ -25,13 +25,25 @@ inline fun Flow.subscribeSafely( } /** - * Use [subscribeSafelyWithoutExceptions], but all exceptions inside of [safely] will be skipped + * Use [subscribeSafelyWithoutExceptions], but all exceptions will be passed to [defaultSafelyExceptionHandler] */ inline fun Flow.subscribeSafelyWithoutExceptions( scope: CoroutineScope, noinline block: suspend (T) -> Unit -) = subscribeSafely( - scope, - {}, - block -) +) = subscribe(scope) { + safelyWithoutExceptions { + block(it) + } +} + +/** + * Use [subscribeSafelyWithoutExceptions], but all exceptions inside of [safely] will be skipped + */ +inline fun Flow.subscribeSafelySkippingExceptions( + scope: CoroutineScope, + noinline block: suspend (T) -> Unit +) = subscribe(scope) { + safelyWithoutExceptions({ /* skip exceptions */ }) { + block(it) + } +}