diff --git a/kotlin-result-coroutines/src/commonMain/kotlin/com/github/michaelbull/result/coroutines/RunSuspendCatching.kt b/kotlin-result-coroutines/src/commonMain/kotlin/com/github/michaelbull/result/coroutines/RunSuspendCatching.kt new file mode 100644 index 0000000..c63151e --- /dev/null +++ b/kotlin-result-coroutines/src/commonMain/kotlin/com/github/michaelbull/result/coroutines/RunSuspendCatching.kt @@ -0,0 +1,4 @@ +package com.github.michaelbull.result.coroutines + +class RunSuspendCatching { +} diff --git a/kotlin-result-coroutines/src/jvmTest/kotlin/com/github/michaelbull/result/coroutines/RunSuspendCatchingTest.kt b/kotlin-result-coroutines/src/jvmTest/kotlin/com/github/michaelbull/result/coroutines/RunSuspendCatchingTest.kt new file mode 100644 index 0000000..b244ad6 --- /dev/null +++ b/kotlin-result-coroutines/src/jvmTest/kotlin/com/github/michaelbull/result/coroutines/RunSuspendCatchingTest.kt @@ -0,0 +1,11 @@ +package com.github.michaelbull.result.coroutines + +import kotlin.test.Test + +class RunSuspendCatchingTest { + + @Test + fun propogatesCoroutineCancellation() { + val testDispatcher = TestCoroutineDispatcher() + } +} diff --git a/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/ThrowIfUnless.kt b/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/ThrowIfUnless.kt index ad93c40..087e6ad 100644 --- a/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/ThrowIfUnless.kt +++ b/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/ThrowIfUnless.kt @@ -1,5 +1,8 @@ package com.github.michaelbull.result +import kotlin.contracts.InvocationKind +import kotlin.contracts.contract + /** * If the [Result] is [Err] and contains a [Throwable], throws the [error][Err.error] * if the [predicate] returns true. @@ -8,8 +11,10 @@ package com.github.michaelbull.result */ public inline fun Result.throwIf( predicate: (E) -> Boolean -): Result = - onFailure { e -> if (predicate(e)) throw e } +): Result { + contract { callsInPlace(predicate, InvocationKind.AT_MOST_ONCE) } + return onFailure { e -> if (predicate(e)) throw e } +} /** * If the [Result] is [Err] and contains a [Throwable], throws the [error][Err.error]