diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2022-06-04 14:41:52 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-04 09:11:52 +0000 |
commit | fee75104962548404ed2ffc4f6ef9c397b86683f (patch) | |
tree | 9a33007643184f72bcd98ab70d0cfc91e4e87f7e /coroutine-utils | |
parent | ac94b88d870f6c589e051723cf95bfd04032949d (diff) |
Miscellaneous cleanups (#1934)
* build-logic: cleanups
* coroutine-utils-testing: cleanups
* coroutine-utils: cleanups
* crypto-common: cleanups
* crypto-pgpainless: cleanups
* format-common: cleanups
Diffstat (limited to 'coroutine-utils')
-rw-r--r-- | coroutine-utils/src/main/kotlin/dev/msfjarvis/aps/util/coroutines/RunSuspendCatching.kt | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/coroutine-utils/src/main/kotlin/dev/msfjarvis/aps/util/coroutines/RunSuspendCatching.kt b/coroutine-utils/src/main/kotlin/dev/msfjarvis/aps/util/coroutines/RunSuspendCatching.kt index 7e5b906c..4ba68159 100644 --- a/coroutine-utils/src/main/kotlin/dev/msfjarvis/aps/util/coroutines/RunSuspendCatching.kt +++ b/coroutine-utils/src/main/kotlin/dev/msfjarvis/aps/util/coroutines/RunSuspendCatching.kt @@ -12,11 +12,11 @@ import kotlin.contracts.contract import kotlinx.coroutines.CancellationException /** - * Calls the specified function [block] with [this] value as its receiver and returns its - * encapsulated result if invocation was successful, catching any [Throwable] except - * [CancellationException] that was thrown from the [block] function execution and encapsulating it - * as a failure. + * Calls the specified function [block] and returns its encapsulated result if invocation was + * successful, catching any [Throwable] except [CancellationException] that was thrown from the + * [block] function execution and encapsulating it as a failure. */ +@OptIn(ExperimentalContracts::class) public suspend inline fun <V> runSuspendCatching(block: () -> V): Result<V, Throwable> { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } @@ -34,6 +34,7 @@ public suspend inline fun <V> runSuspendCatching(block: () -> V): Result<V, Thro * [CancellationException] that was thrown from the [block] function execution and encapsulating it * as a failure. */ +@OptIn(ExperimentalContracts::class) public suspend inline infix fun <T, V> T.runSuspendCatching( block: T.() -> V ): Result<V, Throwable> { |