177
// The result is initInterval * (backoffCoefficient ^ (currentAttempt - 1)).
178
// If the calculation overflows int64, it returns the maximum possible duration. A negative result will also never be returned.
179
>
func ExponentialBackoffAlgorithm(initInterval *durationpb.Duration, backoffCoefficient float64, currentAttempt int32) time.Duration {
retry.go
180
>
result := float64(initInterval.AsDuration().Nanoseconds()) * math.Pow(backoffCoefficient, float64(currentAttempt-1))
181
>
return time.Duration(max(0, min(int64(result), math.MaxInt64)))
182
>
}
183
184
// MakeBackoffAlgorithm creates a BackoffCalculatorAlgorithmFunc that returns a fixed delay if requestedDelay is non-nil,