File tree Expand file tree Collapse file tree 3 files changed +11
-5
lines changed
commonMain/kotlin/com/github/michaelbull/retry
commonTest/kotlin/com/github/michaelbull/retry Expand file tree Collapse file tree 3 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ import kotlin.coroutines.cancellation.CancellationException
1313
1414/* *
1515 * Calls the specified function [block] and returns its result if invocation was successful, catching any [Throwable]
16- * exception that was thrown from the [block] function executing and retrying the invocation according to
16+ * exception that was thrown from the [block] function execution and retrying the invocation according to
1717 * [instructions][RetryInstruction] from the [policy].
1818 */
1919public suspend inline fun <T > retry (policy : RetryPolicy <Throwable >, block : () -> T ): T {
Original file line number Diff line number Diff line change @@ -2,12 +2,18 @@ package com.github.michaelbull.retry
22
33import com.github.michaelbull.retry.instruction.RetryInstruction
44import com.github.michaelbull.retry.policy.RetryPolicy
5+ import kotlin.contracts.InvocationKind
6+ import kotlin.contracts.contract
57
68/* *
79 * Calls the specified function [block] and returns its result if invocation was successful, catching any [Throwable]
8- * exception that was thrown from the [block] function executing and retrying the invocation according to
10+ * exception that was thrown from the [block] function execution and retrying the invocation according to
911 * [instructions][RetryInstruction] from the [policy].
1012 */
1113public suspend inline fun <T > runRetrying (policy : RetryPolicy <Throwable >, block : () -> T ): T {
14+ contract {
15+ callsInPlace(block, InvocationKind .AT_LEAST_ONCE )
16+ }
17+
1218 return retry(policy, block)
1319}
Original file line number Diff line number Diff line change @@ -151,9 +151,9 @@ class RetryTest {
151151
152152 if (attempts == 15 ) {
153153 cancel()
154- } else {
155- throw AttemptsException (attempts)
156154 }
155+
156+ throw AttemptsException (attempts)
157157 }
158158 }
159159
@@ -170,7 +170,7 @@ class RetryTest {
170170 }
171171
172172 @Test
173- fun cancelRetryFromWithinChildJob () = runTest {
173+ fun cancelRetryWithinChildJob () = runTest {
174174 val every20ms = constantDelay<Throwable >(20 )
175175 var attempts = 0
176176
You can’t perform that action at this time.
0 commit comments