delay method

Duration delay(
  1. int attempt
)

Delay after attempt number of attempts.

This is computed as pow(2, attempt) * delayFactor, then is multiplied by between -randomizationFactor and randomizationFactor at random.

Implementation

Duration delay(int attempt) {
  assert(attempt >= 0, 'attempt cannot be negative');
  if (attempt <= 0) {
    return Duration.zero;
  }
  final rf = (randomizationFactor * (_rand.nextDouble() * 2 - 1) + 1);
  final exp = math.min(attempt, 31); // prevent overflows.
  final delay = (delayFactor * math.pow(2.0, exp) * rf);
  return delay < maxDelay ? delay : maxDelay;
}