DefaultRetryPolicy

A default implementation of the RetryPolicy interface.

This class orchestrates the execution of a code block with retry logic based on the provided RetryPolicyConfig. It will attempt to execute the block up to maxAttempts times. If an exception occurs, it consults RetryPolicyConfig.shouldRetry and, if a retry is warranted, it calls RetryPolicyConfig.onRetry, waits per RetryPolicyConfig.backoffStrategy, and tries again. If block completes successfully and RetryPolicyConfig.shouldRetryResult returns true, the same retry path is used (with RetryableResultException passed to RetryPolicyConfig.onRetry). If all attempts fail with exceptions, the last caught exception is rethrown. If attempts are exhausted due to RetryPolicyConfig.shouldRetryResult, the last returned value is returned.

Parameters

config

The configuration that defines the retry behavior, including the number of attempts, the backoff strategy, and conditions for retrying.

See also

Constructors

Link copied to clipboard
constructor(config: RetryPolicyConfig)

Functions

Link copied to clipboard
open suspend override fun <T> execute(block: suspend () -> T): T

Executes block and retries on failure according to the policy configuration.

Link copied to clipboard

Returns a point-in-time snapshot of the retry policy configuration.