RetryPolicy class sealed

Whether a failed attempt is tried again — the retry option.

A query or mutation function that throws is retried according to this policy, with RetryDelay deciding the wait in between. While retrying, the result stays pending (or keeps its old data) and reports the failure so far through failureCount and failureReason; only when the policy gives up does the result become an error.

Default: RetryPolicy.times (3) for queries — three retries after the first failure, four attempts in all — and RetryPolicy.never for mutations.

retry: RetryPolicy.never          // fail on the first error
retry: const RetryPolicy.times(5) // up to five retries
retry: RetryPolicy.always         // retry until it succeeds
retry: RetryPolicy.when(
  (failureCount, error, stackTrace) =>
      error is! NotFoundException && failureCount < 3,
)
Annotations

Constructors

RetryPolicy.times(int count)
Retry up to count times, so at most count + 1 attempts run; RetryPolicy.times(3) is the default for queries: up to three retries after the first failure (TanStack Query: retry: 3).
const
factory
RetryPolicy.when(bool predicate(int failureCount, Object error, StackTrace stackTrace))
Decided per failure (TanStack Query: retry: (failureCount, error) => …). failureCount is how many attempts had already failed before the one being decided, so it is 0 on the first decision.
const
factory

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

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
shouldRetry(int failureCount, Object error, StackTrace stackTrace) → bool
Whether to try again after an attempt threw error, given that failureCount attempts had failed before it.
toString() → String
A string representation of this object.
inherited

Operators

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

Constants

always → const RetryPolicy
Retry until an attempt succeeds, however often it fails (TanStack Query: retry: true).
never → const RetryPolicy
Never retry: the first failure is the error — the default for mutations (TanStack Query: retry: false).