retry If With Capped Backoff
suspend fun <R> retryIfWithCappedBackoff(retries: Long = 3, base: Duration = 200.milliseconds, maxDelay: Duration = 10.seconds, factor: Double = 2.0, shouldRetry: (Throwable) -> Boolean, block: suspend () -> R): R(source)
Executes a suspend operation with retry using exponential backoff capped at a maximum delay, like retryWithCappedBackoff - but, unlike that, only for exceptions matching shouldRetry. Combines retryWithCappedBackoff's bounded backoff with retryIf's conditional retry.
Return
The result of the successful execution
Parameters
retries
The maximum number of retry attempts (defaults to 3)
base
The base duration for exponential backoff (defaults to 200 milliseconds)
max Delay
The maximum delay between retries
factor
The exponential factor (defaults to 2.0)
should Retry
Predicate that receives the exception and returns true to retry
block
The suspend operation to execute
Type Parameters
R
The return type of the suspend operation
Throws
if shouldRetry returns false or all retries are exhausted