retry Or Default
suspend fun <R> retryOrDefault(retries: Long = 3, base: Duration = 200.milliseconds, factor: Double = 2.0, fallback: suspend (Throwable) -> R, block: suspend () -> R): R(source)
Executes a suspend operation with retry and returns a fallback value if all retries fail.
Return
The result of successful execution or the fallback value
Example usage:
val user = retryOrDefault(retries = 3, fallback = { User.anonymous() }) {
userService.fetchUser("user123")
}Content copied to clipboard
Parameters
retries
The maximum number of retry attempts (defaults to 3)
base
The base duration for exponential backoff (defaults to 200 milliseconds)
factor
The exponential factor (defaults to 2.0)
fallback
The fallback value provider that receives the last exception
block
The suspend operation to execute
Type Parameters
R
The return type of the suspend operation