Skip to content

Retry Backoff & Cancellation ​

Network operations can fail intermittently due to temporary outages, rate limits, or packet drops. fquery_core provides automatic retries and cancellation management via RetryResolver.


Automatic Retries ​

When configuring a query or mutation:

  • retryCount: Number of times to retry after initial failure (defaults to 3).
  • retryDelay: Duration to wait between attempts (defaults to 1.5s).
dart
final observer = QueryObserver<User, SocketException>(
  cache: cache,
  queryKey: QueryKey(['profile']),
  queryFn: fetchUserProfile,
  retryCount: 3,
  retryDelay: Duration(seconds: 2),
);

Typed Error Catching ​

fquery_core catches errors matching the specified TError type. If an unexpected error is thrown (e.g. an unhandled assertion or syntax error), the resolver halts retries immediately to avoid masking bugs.


Cancellation & Resource Management ​

When an observer is disabled or disposed while a request is in flight:

dart
// Toggling enabled to false cancels in-flight requests and refetch timers
observer.updateOptions(
  QueryOptions(
    queryKey: observer.queryKey,
    queryFn: observer.queryFn,
    enabled: false,
  ),
);

// Disposing completely detaches observer and cancels in-flight resolvers
observer.dispose();

When cancelled:

  • RetryResolver immediately halts its retry loop.
  • Any pending delay timer is cancelled.
  • The cache transitions via DispatchAction.cancelFetch, preventing lingering or stale responses from overwriting newer data.

Released under the MIT License.