retryWithFibonacci

suspend fun <R> retryWithFibonacci(retries: Long = 5, base: Duration = 100.milliseconds, block: suspend () -> R): R(source)

Executes a suspend operation with retry using Fibonacci sequence for delays.

The Fibonacci sequence provides a middle ground between constant and exponential backoff, growing more gradually than exponential but faster than constant delays.

Return

The result of the successful execution

Parameters

retries

The maximum number of retry attempts (defaults to 5)

base

The base delay unit (defaults to 100 milliseconds)

block

The suspend operation to execute

Type Parameters

R

The return type of the suspend operation

Throws

if all retry attempts fail

Example usage:

val data = retryWithFibonacci(retries = 8) {
apiClient.fetchData()
}