in src/setup-bazelisk/src.main.kts [251:275]
suspend fun <T> retry(body: suspend () -> T): T {
contract {
callsInPlace(body, InvocationKind.AT_LEAST_ONCE)
}
var effectiveDelay = INITIAL_DELAY_MS
for (i in 1..MAX_ATTEMPTS) try {
return body()
} catch (e: Throwable) {
if (e is CancellationException) {
throw e
}
if (i == MAX_ATTEMPTS) {
error("'${e.toString()} (Failed all $MAX_ATTEMPTS attempts)'")
}
if (i > 1) {
effectiveDelay = backOff(effectiveDelay, e)
}
println("Retry $i of $MAX_ATTEMPTS failed with '${e.toString()}'. Retrying in ${effectiveDelay}ms")
if (effectiveDelay > 0) {
delay(effectiveDelay)
}
}
error("Should not be reached")
}