From 6f5c6e5ebeda4dbed68f08ea427b49b517a2289f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 2 Nov 2020 21:25:33 +0600 Subject: [PATCH] safelyWithoutExceptions --- CHANGELOG.md | 3 +++ .../kotlin/dev/inmo/micro_utils/coroutines/HandleSafely.kt | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca8c36fe4ad..a99129f2557 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.2.5 +* `Coroutines` + * Function `safelyWithoutExceptions` + ## 0.2.4 * `Versions` diff --git a/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/HandleSafely.kt b/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/HandleSafely.kt index c58ba10c3d3..64d3dc86c1d 100644 --- a/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/HandleSafely.kt +++ b/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/HandleSafely.kt @@ -21,3 +21,10 @@ suspend inline fun safely( onException(e) } } + +/** + * Shortcut for [safely] without exception handler (instead of this you will receive null as a result) + */ +suspend inline fun safelyWithoutExceptions( + noinline block: suspend CoroutineScope.() -> T +): T? = safely({ null }, block)