RetryConfigBuilder

class RetryConfigBuilder(val baseConfig: RetryConfig = defaultRetryConfig) : ConfigBuilder<RetryConfig> (source)

Builder for configuring a RetryConfig instance. Use retryConfig to create one.

Constructors

Link copied to clipboard
constructor(baseConfig: RetryConfig = defaultRetryConfig)

Properties

Link copied to clipboard
open override val baseConfig: RetryConfig

The base configuration object to be used as a starting point for building the final configuration object.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

The maximum number of attempts (including the initial call as the first attempt).

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
open override fun build(): RetryConfig

Builds the RetryConfig instance with the configured properties.

Link copied to clipboard
fun constantDelay(duration: Duration, randomizationFactor: Double = 0.0)

Configures the retry delay strategy to use a constant delay. The delay between retries is calculated using the formula:

Link copied to clipboard
fun customDelay(delayStrategy: RetryDelayStrategy)

Configures the retry delay strategy to use a custom delay strategy.

Link copied to clipboard

Configures the retry delay strategy to use a custom delay provider. In contrast to customDelay, this method enables caller control over the delay provider (which is the kotlinx.coroutines.delay by default) and optional additional state between retries. See RetryCtxDelayProvider for more information and examples of usage.

Link copied to clipboard

Disables the exception handler. By default, the exception, if any, is thrown.

Link copied to clipboard

Configures the exception handler to use when retries are exhausted. By default, the exception, if any, is thrown. For example, if maximum attempts are reached and the exception handler is not set, the exception will be thrown. Use this method to handle exceptions that occur during the retry operation in a custom way (e.g., logging specific exceptions).

Link copied to clipboard
fun exponentialDelay(initialDelay: Duration = 500L.milliseconds, multiplier: Double = 2.0, maxDelay: Duration = 1.minutes, randomizationFactor: Double = 0.0)

Configures the retry delay strategy to use the exponential backoff algorithm. The delay between retries is calculated using the formula: The algorithm is based on the formula:

Link copied to clipboard
fun linearDelay(initialDelay: Duration = 500L.milliseconds, multiplier: Double = 1.0, maxDelay: Duration = 1.minutes, randomizationFactor: Double = 0.0)

Configures the retry delay strategy to use the linear backoff algorithm. The delay between retries is calculated using the formula:

Link copied to clipboard
fun noDelay()

Configures the retry delay strategy to have no delay between retries (i.e., retries are immediate and do not use any custom delay provider.

Link copied to clipboard

Configures the retry predicate. The predicate is used to determine if, based on the caught throwable, the operation should be retried.

Link copied to clipboard

Configures the retry on result predicate. The predicate is used to determine if, based on the result of the operation, the operation should be retried.