RetryExecutor class
Runs an action against a RetryPolicy. delayFn/randomFn are
injectable (default to real Future.delayed/Random().nextDouble()) so
a test drives the whole retry loop deterministically and instantly,
never actually waiting real backoff delays — same seam-injection
convention as HapticChoreographer's createTimer.
Typical integration — RemoteConfigService.fetchRemote (or a
CloudSaveProvider call) is exactly the kind of "one flaky network
call" this wraps, without RemoteConfigService itself knowing anything
about retries:
RemoteConfigService(
assetPath: 'assets/remote_config_defaults.json',
fetchRemote: () async {
final result = await RetryExecutor().run(
() => myHttpClient.fetchConfigJson(),
policy: const RetryPolicy(maxAttempts: 3),
retryIf: (error) => error is! FormatException, // bad payload: don't retry
);
return result.value ?? {}; // RemoteConfigService treats {} as "no override"
},
);
Constructors
-
RetryExecutor({Future<
void> delayFn(Duration delay)?, double randomFn()?})
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
-
run<
T> (Future< T> action(), {RetryPolicy policy = const RetryPolicy(), bool retryIf(Object error)?, void onAttempt(RetryAttemptEvent event)?, bool isCancelled()?}) → Future<SdkResult< T> > -
Runs
actionunderpolicy.retryIfdecides whether a thrown error is worth retrying (default: always retryable) — a caller checking e.g.error is! FormatExceptioncan stop immediately on a non-transient error instead of burning through every attempt.isCancelledis polled before the first attempt and after every delay; once it returnstruethe loop stops without starting another attempt. The final failure'scause/stackTraceare always preserved in the returned SdkFailure — a retry loop giving up never silently drops the last real error. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited