runCatching for safely and safelyWithoutExceptions

This commit is contained in:
InsanusMokrassar committed 2021-05-25 00:18:46 +06:00
1 parent 00c23c73a8
commit 976ce056c1
2 files changed
+15

No files matched your search

@@ -108,6 +108,13 @@ suspend inline fun <T> safely(
}
}
suspend inline fun <T> runCatchingSafely(
noinline onException: ExceptionHandler<T> = defaultSafelyExceptionHandler,
noinline block: suspend CoroutineScope.() -> T
): Result<T> = 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 <T> safelyWithoutExceptions(
noinline onException: ExceptionHandler<T?> = defaultSafelyWithoutExceptionHandlerWithNull,
noinline block: suspend CoroutineScope.() -> T
): T? = safely(onException, block)
suspend inline fun <T> runCatchingSafelyWithoutExceptions(
noinline onException: ExceptionHandler<T?> = defaultSafelyWithoutExceptionHandlerWithNull,
noinline block: suspend CoroutineScope.() -> T
): Result<T?> = runCatching {
safelyWithoutExceptions(onException, block)
}