retry With History
suspend fun <R> retryWithHistory(retries: Long = 3, base: Duration = 200.milliseconds, factor: Double = 2.0, clock: Clock = Clock.System, block: suspend () -> R): RetryResult<R>(source)
Executes a suspend operation with retry and collects detailed history of all attempts.
Return
A RetryResult containing the final result and detailed attempt history
Example usage:
val result = retryWithHistory(retries = 5) {
apiClient.fetchData()
}
println("Took ${result.attemptCount} attempts")
println("Total duration: ${result.totalDuration}")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)
block
The suspend operation to execute
Type Parameters
R
The return type of the suspend operation