A pluggable policy that decides whether a failed request is retried and how long to wait before the next attempt.
Implement this to fully control retry behavior—backoff shape, which
failures are retryable, and idempotency handling. The default
implementation is RetryConfig; pass any RetryStrategy wherever a
retryConfig is accepted.
class ConstantBackoff implements RetryStrategy {
const ConstantBackoff({this.maxAttempts = 3});
final int maxAttempts;
@override
FutureOr<Duration?> nextDelay(RetryContext ctx) {
if (ctx.attempt > maxAttempts) return null; // give up
if (ctx.isProcedure && ctx.isAmbiguous) return null; // stay safe
return ctx.retryAfter ?? const Duration(seconds: 1);
}
}
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
nextDelay(
RetryContext context) → FutureOr< Duration?> -
Returns the delay to wait before the next attempt, or
nullto stop retrying and let the original error propagate. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited