withRetry<T> function
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,
),
);
}