RetryWithJitter class
Decorator that adds random jitter to any retry policy
Jitter helps prevent thundering herd problems when multiple clients retry simultaneously.
Example:
final limit = fLimit(2);
await limit(
() => fetchData(),
retry: RetryWithJitter(
RetryExponential(
maxAttempts: 3,
baseDelay: Duration(seconds: 1),
),
jitterFactor: 0.5,
),
);
// With jitterFactor 0.5, a 2s delay becomes 1s-3s (2s ± 50%)
- Inheritance
-
- Object
- RetryPolicy
- RetryWithJitter
Constructors
- RetryWithJitter(RetryPolicy inner, {double jitterFactor = 0.5})
- Creates a jittered retry policy
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- inner → RetryPolicy
-
The underlying retry policy to decorate
final
- jitterFactor → double
-
Jitter factor (0.0 to 1.0)
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
nextDelay(
int attempt, Object error, StackTrace stackTrace) → Duration? -
Returns the delay before the next retry, or null for immediate retry
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
shouldRetry(
int attempt, Object error, StackTrace stackTrace) → bool -
Whether the task should be retried
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited