delay method

  1. @override
Duration delay(
  1. int attempt
)
override

Returns the delay before the given attempt (0-indexed).

Implementation

@override
Duration delay(int attempt) {
  final ms = baseDelay.inMilliseconds * math.pow(2, attempt);
  var capped = math.min(ms.toInt(), maxDelay.inMilliseconds);

  if (withJitter) {
    // Apply ±25 % jitter.
    final jitter = (capped * 0.25).toInt();
    capped = capped - jitter + _random.nextInt(jitter * 2 + 1);
  }

  return Duration(milliseconds: capped);
}