Skip to content

Releases: michaelbull/kotlin-retry

2.0.1

11 Apr 17:33
Compare
Choose a tag to compare

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

03 Mar 23:01
Compare
Choose a tag to compare

Version 2.0.0 represents a major breaking change in the form of an underlying rewrite and support 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

07 Aug 08:49
Compare
Choose a tag to compare

1.0.8

07 Feb 13:41
Compare
Choose a tag to compare
  • 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

30 Jan 18:57
Compare
Choose a tag to compare

1.0.6

26 Sep 14:07
Compare
Choose a tag to compare

1.0.5

12 Feb 15:31
Compare
Choose a tag to compare
  • 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

20 Dec 15:14
Compare
Choose a tag to compare
  • Update dependencies (31dfa73)
  • Replace travis with github actions (934f05b)

1.0.3

21 Oct 11:07
Compare
Choose a tag to compare
  • Add single LongRange argument factory functions for backoff strategies (548a40d)

1.0.2

20 Sep 19:48
Compare
Choose a tag to compare
  • Handle merging of zero-delay policies (4e1cf75)
    • Fixes #2
  • Update dependencies (58571a2)
    • Kotlin Coroutines from 1.3.0 to 1.3.1
    • Gradle from 5.6 to 5.6.2