defaultRetry static method
The default implementation of retry.
The function takes two parameters:
retryCount
: The number of times the provider has been retried (starting at 0).error
: The error that caused the retry.
The function takes two parameters:
retryCount
: The number of times the provider has been retried (starting at 0).error
: The error that caused the retry.
The default implementation:
- 10 retries
- starts with a delay of 200ms
- doubles the delay on each retry up to 6.4 seconds
- retries all failures
- ignores
ProviderException
s (which happens when a provider rethrows the error of another provider) - ignores Errors (which are generally programming errors)
To learn more about retry logic, see Automatic Retry.
Implementation
static Duration? defaultRetry(
int retryCount,
Object error, {
int maxRetries = 10,
Duration maxDelay = const Duration(milliseconds: 6400),
Duration minDelay = const Duration(milliseconds: 200),
}) {
if (retryCount >= maxRetries) return null;
if (error is ProviderException || error is Error) return null;
final delay = minDelay * math.pow(2, retryCount).toInt();
if (delay > maxDelay) return maxDelay;
return delay;
}