RetryPolicy

interface RetryPolicy

Decides whether to retry a failed operation, and how long to wait first.

One policy may serve many concurrent operations, so implementations must be thread-safe and should return quickly without blocking. Java implementations extend BaseMillisRetryPolicy, since Java cannot return a Duration.

Inheritors

Functions

Link copied to clipboard
abstract fun nextRetryDelay(failedAttempts: Int): Duration

Returns the delay before the next attempt once failedAttempts attempts have failed, and is called only after shouldRetry returned true. A zero or negative delay retries at once, and Duration.INFINITE waits until the retrying coroutine is canceled.

Link copied to clipboard
abstract fun shouldRetry(failure: Exception, failedAttempts: Int): Boolean

Returns whether to retry once failedAttempts attempts (at least 1) have failed, the last with failure.