calculateDelay method

  1. @override
Duration calculateDelay(
  1. int attemptNumber
)
override

Calculates the delay before the next reconnection attempt.

Implementation

@override
Duration calculateDelay(int attemptNumber) {
  // Calculate exponential delay
  final exponentialDelay = initialDelay.inMilliseconds *
      (pow(multiplier, attemptNumber - 1).toInt());

  // Apply maximum delay cap
  final cappedDelay = exponentialDelay.clamp(0, maxDelay.inMilliseconds);

  // Add randomization to prevent thundering herd
  final randomFactor =
      1.0 + (randomizationFactor * (Random().nextDouble() * 2 - 1));
  final finalDelay = (cappedDelay * randomFactor).round();

  return Duration(milliseconds: finalDelay);
}