diff --git a/CHANGELOG.md b/CHANGELOG.md index 38529067b90..31a461020f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ default value * New value `defaultSafelyWithoutExceptionHandlerWithNull` which is used in all `*WithoutExceptions` by default * Analogs of `launch` and `async` for `safely` and `safelyWithoutExceptions` were added + * Analogs of `runCatching` for `safely` and `safelyWithoutExceptions` were added ## 0.5.2 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 84dedadb58f..2472837ef50 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 @@ -108,6 +108,13 @@ suspend inline fun safely( } } +suspend inline fun runCatchingSafely( + noinline onException: ExceptionHandler = defaultSafelyExceptionHandler, + noinline block: suspend CoroutineScope.() -> T +): Result = runCatching { + safely(onException, block) +} + /** * Use this handler in cases you wish to include handling of exceptions by [defaultSafelyWithoutExceptionHandler] and * returning null at one time @@ -129,3 +136,10 @@ suspend inline fun safelyWithoutExceptions( noinline onException: ExceptionHandler = defaultSafelyWithoutExceptionHandlerWithNull, noinline block: suspend CoroutineScope.() -> T ): T? = safely(onException, block) + +suspend inline fun runCatchingSafelyWithoutExceptions( + noinline onException: ExceptionHandler = defaultSafelyWithoutExceptionHandlerWithNull, + noinline block: suspend CoroutineScope.() -> T +): Result = runCatching { + safelyWithoutExceptions(onException, block) +}