retry
suspend fun <T> retry(times: Int, delayBetween: Duration = Duration.ZERO, block: suspend (attempt: Int) -> T): T
Runs block up to times attempts and returns the first successful result.
The attempt number passed to block starts at 1. After a failed attempt this function suspends for delayBetween, then tries again. The failure of the final attempt is rethrown unchanged.
Cancellation: a CancellationException thrown by block or while delaying is rethrown immediately and is never retried.
Parameters
times
the maximum number of attempts, at least 1.
delayBetween
the pause between consecutive attempts.
Throws
if times is less than 1 or delayBetween is negative.