RetryOptions class

Object holding options for retrying a function.

With the default configuration functions will be retried up-to 7 times (8 attempts in total), sleeping 1st, 2nd, 3rd, ..., 7th attempt:

  1. 400 ms +/- 25%
  2. 800 ms +/- 25%
  3. 1600 ms +/- 25%
  4. 3200 ms +/- 25%
  5. 6400 ms +/- 25%
  6. 12800 ms +/- 25%
  7. 25600 ms +/- 25%

Example

final r = RetryOptions();
final response = await r.retry(
  // Make a GET request
  () => http.get('https://google.com').timeout(Duration(seconds: 5)),
  // Retry on SocketException or TimeoutException
  retryIf: (e) => e is SocketException || e is TimeoutException,
);
print(response.body);

Constructors

RetryOptions({Duration delayFactor = const Duration(milliseconds: 200), double randomizationFactor = 0.25, Duration maxDelay = const Duration(seconds: 30), int maxAttempts = 8})
Create a set of RetryOptions.
const

Properties

delayFactor Duration
Delay factor to double after every attempt.
final
hashCode int
The hash code for this object.
read-onlyinherited
maxAttempts int
Maximum number of attempts before giving up, defaults to 8.
final
maxDelay Duration
Maximum delay between retries, defaults to 30 seconds.
final
randomizationFactor double
Percentage the delay should be randomized, given as fraction between 0 and 1.
final
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited

Methods

delay(int attempt) Duration
Delay after attempt number of attempts.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
retry<T>(FutureOr<T> fn(), {FutureOr<bool> retryIf(Exception), FutureOr<void> onRetry(Exception)}) Future<T>
Call fn retrying so long as retryIf return true for the exception thrown.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited