RetryPolicyConfig

Configuration class for defining the behavior of a RetryPolicy.

This class holds the parameters that control how and when retries are performed. It is typically used within a DSL to configure a retry mechanism.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

The strategy to determine the delay between retry attempts. Defaults to ExponentialBackoff.

Link copied to clipboard

The maximum number of times an operation will be attempted. Includes the initial attempt. Defaults to 3.

Link copied to clipboard
var onRetry: suspend (attempt: Int, error: Throwable) -> Unit

A suspendable callback function that is executed before each retry attempt. It receives the current attempt number and the error that caused the failure. Defaults to an empty lambda.

Link copied to clipboard

If set, each attempt (including the first) is limited to this duration. When exceeded, the attempt is cancelled and may be retried according to shouldRetry (e.g. kotlinx.coroutines.TimeoutCancellationException is typically retryable). Use this when you want a timeout per attempt rather than a single global timeout from a TimeoutPolicy. Defaults to null (no per-attempt timeout).

Link copied to clipboard

A predicate to decide if a retry should be performed based on the Throwable that was caught. Defaults to a lambda that always returns true, meaning any exception will trigger a retry.

Link copied to clipboard

Optional predicate run after block completes without throwing. Return true to treat the outcome as needing another attempt (same maxAttempts budget as exception retries). Return false to accept the value. Default is null (only shouldRetry applies). When true, onRetry is invoked with RetryableResultException (see RetryableResultException.lastValue). If maxAttempts is exhausted while the predicate keeps returning true, the last returned value is returned (unlike exception exhaustion, which rethrows the last Throwable).