Skip to content

Releases: michaelbull/kotlin-retry

2.0.2

Choose a tag to compare

@michaelbull michaelbull released this 04 Aug 12:01
  • Fix stale kdoc references in stopAt{Attempts,Retries} (59ddc8c)
  • Replace deprecated wrapper-validation-action (7a0d2cb)
  • Update Gradle to 8.12 (4357be4)
  • Update dependencies (31df6ac)
  • Adopt gradle-maven-publish-plugin (a78ec24)

2.0.1

Choose a tag to compare

@michaelbull michaelbull released this 11 Apr 17:33

This release introduces the kotlin-retry-result subproject, leveraging the Result<V, E> type from kotlin-result for code that must be retried but returns an Err instead of throwing an Exception.

See the README section for a full example.

To install the new extension library:

repositories {
    mavenCentral()
}

dependencies {
    implementation("com.michael-bull.kotlin-retry:kotlin-retry:2.0.1")
    implementation("com.michael-bull.kotlin-retry:kotlin-retry-result:2.0.1")
}

2.0.0

Choose a tag to compare

@michaelbull michaelbull released this 03 Mar 23:01

Version 2.0.0 represents a major breaking change in the form of an underlying rewrite and support for all three tiers of Kotlin/Native.

Multiplatform

The project has been converted to be multiplatform, matching compatibility with kotlinx-coroutines support for all three tiers of Kotlin/Native.

The full list of platform targets can be found in the kotlin-conventions Gradle plugin.

Policy Authoring Changes

The implementation no longer relies on CoroutineContext to persist the state of retry attempts. Instead, the RetryPolicy (now a functional interface) is passed the attempt that just failed. This makes it clear on the callsite what information about the failed attempt is available, instead of being expected to know what fields are in the coroutineContext.retryStatus.

The attempt argument for a RetryPolicy contains:

  • The failure as a generic.
    • In the default case of invoking the retry or runRetrying function, this will be Throwable, however leaves future oppurtunity for a Result-backed retry function that uses an Err instead of a Throwable.
  • A zero-based attempt number.
    • 0 means the invocation of the block has failed and no attempts have been made to retry invoking the block.
    • 1 means the invocation of the block has failed, and one attempt to retry invoking the block also failed - totalling two attempts and one retry.
  • The delay between the failed attempt and the attempt prior.
  • The cumulativeDelay across all attempts.

Before:

public fun binaryExponentialBackoff(min: Long, max: Long): RetryPolicy<*> {
    require(min > 0) { "min must be positive, but was $min" }
    require(max > 0) { "max must be positive, but was $max" }

    return {
        val attempt = coroutineContext.retryStatus.attempt
        val delay = min(max, min saturatedMultiply attempt.binaryExponential())

        RetryAfter(delay)
    }
}

After:

public fun <E> binaryExponentialBackoff(min: Long, max: Long): RetryPolicy<E> {
    require(min > 0) { "min must be positive, but was $min" }
    require(max > 0) { "max must be positive, but was $max" }

    return RetryPolicy { attempt ->
        val delay = min(max, min saturatedMultiply attempt.number.binaryExponential())
        RetryAfter(delay)
    }
}

Function Changes

Various functions have been added, renamed, or their signature otherwise changed to comply with the rewrite.

Renamed

  • maxDelay -> delayAtMost
  • limitAttempts -> stopAtAttempts
  • limitByDelay -> stopAtDelay
  • limitByCumulativeDelay -> stopAtCumulativeDelay
  • retryIf -> continueIf
  • retryUnless -> continueUnless

Added

  • delayAtLeast
  • delayAtMost
  • delayIn
  • stopAtRetries
  • stopIf
  • stopUnless

1.0.9

Choose a tag to compare

@michaelbull michaelbull released this 07 Aug 08:49

1.0.8

Choose a tag to compare

@michaelbull michaelbull released this 07 Feb 13:41
  • Add retryUnless policy (a0b7174)
    • Facilitates creating a RetryPolicy that only retries if a given predicate is not satisfied. Analogous to takeUnless in the stdlib.

1.0.7

Choose a tag to compare

@michaelbull michaelbull released this 30 Jan 18:57

1.0.6

Choose a tag to compare

@michaelbull michaelbull released this 26 Sep 14:07

1.0.5

Choose a tag to compare

@michaelbull michaelbull released this 12 Feb 15:31
  • Add kotlin.code.style=official to gradle.properties (fb8b110)
  • Update gradle to 6.2-rc-2 (cfd9131)
  • Update dependencies (35c30c1)
  • Replace bintray with maven central (25db7ac)

1.0.4

Choose a tag to compare

@michaelbull michaelbull released this 20 Dec 15:14
  • Update dependencies (31dfa73)
  • Replace travis with github actions (934f05b)

1.0.3

Choose a tag to compare

@michaelbull michaelbull released this 21 Oct 11:07
  • Add single LongRange argument factory functions for backoff strategies (548a40d)