withRetry<T> function

Future<T> withRetry<T>(
  1. Future<T> fn(), {
  2. int? attempts,
  3. int? baseDelayMs,
  4. int? maxDelayMs,
  5. double? jitter,
  6. bool shouldRetry(
    1. Object error,
    2. int attempt
    )?,
})

Retries an async operation with default backoff strategy.

Implementation

Future<T> withRetry<T>(
  Future<T> Function() fn, {
  int? attempts,
  int? baseDelayMs,
  int? maxDelayMs,
  double? jitter,
  bool Function(Object error, int attempt)? shouldRetry,
}) {
  return retryWithPolicy(
    (_) => fn(),
    RetryPolicy(
      maxAttempts: attempts ?? _defaultAttempts,
      baseDelayMs: baseDelayMs ?? _defaultBaseDelayMs,
      maxDelayMs: maxDelayMs ?? _defaultMaxDelayMs,
      jitter: jitter ?? _defaultJitter,
      shouldRetry: shouldRetry,
    ),
  );
}