calculateDelay method

Duration calculateDelay(
  1. RetryPolicy policy,
  2. int attempt
)

Calculates the delay before the next retry attempt.

attempt is 1-based: attempt 1 just failed, so this returns the delay before attempt 2.

For fixed: always returns RetryPolicyFixed.delay. For exponential: min(initial * multiplier^(attempt-1), maxDelay) with optional jitter of +/-10%.

Implementation

Duration calculateDelay(RetryPolicy policy, int attempt) {
  return switch (policy) {
    RetryPolicyNone() => Duration.zero,
    RetryPolicyFixed(delay: final d) => d,
    RetryPolicyExponential() => _exponentialDelay(policy, attempt),
  };
}