aboutsummaryrefslogtreecommitdiff
path: root/coroutine-utils
diff options
context:
space:
mode:
Diffstat (limited to 'coroutine-utils')
-rw-r--r--coroutine-utils/src/main/kotlin/dev/msfjarvis/aps/util/coroutines/RunSuspendCatching.kt9
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> {