Retry<St> mixin
This mixin will retry the reduce method if it throws an error.
Note: If the before
method throws an error, the retry will NOT happen.
- Initial Delay: The delay before the first retry attempt.
- Multiplier: The factor by which the delay increases for each subsequent retry.
- Maximum Retries: The maximum number of retries before giving up.
- Maximum Delay: The maximum delay between retries to avoid excessively long wait times.
Default Parameters:
- initialDelay is
350
milliseconds. - multiplier is
2
, which means the default delays are: 350 millis, 700 millis, and 1.4 seg. - maxRetries is
3
, meaning it will try a total of 4 times. - maxDelay is
5
seconds.
If you want to retry unlimited times, you can add the UnlimitedRetries mixin.
Note: The retry delay only starts after the reducer finishes executing. For example, if the reducer takes 1 second to fail, and the retry delay is 350 millis, the first retry will happen 1.35 seconds after the first reducer started.
When the action finally fails, the last error will be rethrown, and the previous ones will be ignored.
You should NOT combine this with CheckInternet or AbortWhenNoInternet, because the retry will not work.
However, for most actions that use Retry, consider also adding NonReentrant to avoid multiple instances of the same action running at the same time:
class MyAction extends ReduxAction<AppState> with Retry, NonReentrant { ... }
Keep in mind that all actions using the Retry mixin will become asynchronous, even if the original action was synchronous.
- Superclass Constraints
- ReduxAction<
St>
- ReduxAction<
Properties
- attempts → int
-
The number of retry attempts so far. If the action has not been retried yet, it will be 0.
If the action finished successfully, it will be equal or less than maxRetries.
If the action failed and gave up, it will be equal to maxRetries plus 1.
no setter
-
dispatch
→ Dispatch<
St> -
Dispatches the action, applying its reducer, and possibly changing the store state.
The action may be sync or async.
no setterinherited
-
dispatchAll
→ List<
ReduxAction< Function(List<St> >ReduxAction< actions, {bool notify})St> > -
Dispatches all given
actions
in parallel, applying their reducer, and possibly changing the store state. It returns the same list ofactions
, so that you can instantiate them inline, but still get a list of them.no setterinherited -
dispatchAndWait
→ DispatchAndWait<
St> -
Dispatches the action, applying its reducer, and possibly changing the store state.
The action may be sync or async. In both cases, it returns a Future that resolves when
the action finishes.
no setterinherited
-
dispatchAndWaitAll
→ Future<
List< Function(List<ReduxAction< >St> >ReduxAction< actions, {bool notify})St> > -
Dispatches all given
actions
in parallel, applying their reducers, and possibly changing the store state. The actions may be sync or async. It returns a Future that resolves when ALL actions finish.no setterinherited -
dispatchAsync
→ DispatchAsync<
St> -
no setterinherited
-
dispatchSync
→ DispatchSync<
St> -
Dispatches the action, applying its reducer, and possibly changing the store state.
However, if the action is ASYNC, it will throw a StoreException.
no setterinherited
- env → Object?
-
Gets the store environment.
This can be used to create a global value, but scoped to the store.
For example, you could have a service locator, here, or a configuration value.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- initialDelay → Duration
-
The delay before the first retry attempt.
no setter
- initialState → St
-
Returns the state as it was when the action was dispatched.
no setterinherited
- isFinished → bool
-
Returns true only if the action finished with no errors.
In other words, if the methods before, reduce and after all finished executing
without throwing any errors.
no setterinherited
- maxDelay → Duration
-
The maximum delay between retries to avoid excessively long wait times.
The default is 5 seconds.
no setter
- maxRetries → int
-
The maximum number of retries before giving up.
Must be greater than 0, otherwise it will not retry.
The total number of attempts is maxRetries + 1.
no setter
- microtask → Future
-
To wait for the next microtask:
await microtask;
no setterinherited - multiplier → double
-
The factor by which the delay increases for each subsequent retry.
Must be greater than 1, otherwise it will be set to 2.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- state → St
-
no setterinherited
- stateTimestamp → DateTime
-
no setterinherited
- status → ActionStatus
-
no setterinherited
-
store
→ Store<
St> -
no setterinherited
Methods
-
abortDispatch(
) → bool -
If abortDispatch returns true, the action will NOT be dispatched:
before
,reduce
andafter
will not be called, and the action will not be visible to the store observers.inherited -
after(
) → void -
This is an optional method that may be overridden to run during action
dispatching, after
reduce
. If this method throws an error, the error will be swallowed (will not throw). So you should only run code that can't throw errors. It may be synchronous only. Note this method will always be called, even if errors were thrown bybefore
orreduce
.inherited -
assertUncompletedFuture(
) → void -
An async reducer (one that returns Future<AppState?>) must never complete without at least
one await, because this may result in state changes being lost. It's up to you to make sure
all code paths in the reducer pass through at least one
await
.inherited -
before(
) → FutureOr< void> -
This is an optional method that may be overridden to run during action
dispatching, before
reduce
. If this method throws an error, thereduce
method will NOT run, but the methodafter
will. It may be synchronous (returningvoid
) ou async (returningFuture<void>
). You should NOT returnFutureOr
.inherited -
clearExceptionFor(
Object actionTypeOrList) → void -
Removes the given
actionTypeOrList
from the list of action types that failed.inherited -
exceptionFor(
Object actionTypeOrList) → UserException? -
Returns the UserException of the
actionTypeOrList
that failed.inherited -
isFailed(
Object actionOrTypeOrList) → bool -
Returns true if an
actionOrActionTypeOrList
failed with an UserException. Note: This method uses the EXACT type inactionOrActionTypeOrList
. Subtypes are not considered.inherited -
isSync(
) → bool -
Returns true if the action is SYNC, and false if the action is ASYNC.
The action is considered SYNC if the
before
method, thereduce
method, and thewrapReduce
methods are all synchronous.inherited -
isWaiting(
Object actionOrTypeOrList) → bool -
You can use isWaiting to check if:
inherited
-
nextDelay(
) → Duration - Start with the initialDelay, and then increase it by multiplier each time this is called. If the delay exceeds maxDelay, it will be set to maxDelay.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
prop<
V> (Object? key) → V -
Gets a property from the store.
This can be used to save global values, but scoped to the store.
For example, you could save timers, streams or futures used by actions.
inherited
-
reduce(
) → FutureOr< St?> -
The
reduce
method is the action reducer. It may read the action state, the store state, and then return a new state (ornull
if no state change is necessary).inherited -
runtimeTypeString(
) → String -
Returns the runtimeType, without the generic part.
inherited
-
setProp(
Object? key, Object? value) → void -
Sets a property in the store.
This can be used to save global values, but scoped to the store.
For example, you could save timers, streams or futures used by actions.
inherited
-
setStore(
Store< St> store) → void -
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
waitAllActions(
List< ReduxAction< actions, {bool completeImmediately = false}) → Future<St> >void> -
Returns a future that completes when ALL given
actions
finished dispatching. You MUST provide at list one action, or an error will be thrown.inherited -
waitCondition(
bool condition(St), {int? timeoutMillis}) → Future< ReduxAction< St> ?> -
Returns a future which will complete when the given state
condition
is true. If the condition is already true when the method is called, the future completes immediately.inherited -
wrapError(
Object error, StackTrace stackTrace) → Object? -
If any error is thrown by
reduce
orbefore
, you have the chance to further process it by usingwrapError
. Usually this is used to wrap the error inside of another that better describes the failed action. For example, if some action converts a String into a number, then instead of throwing a FormatException you could do:inherited -
wrapReduce(
Reducer< St> reduce) → Reducer<St> -
You may wrap the reducer to allow for some pre- or post-processing.
For example, if you want to prevent an async reducer to change the current state,
if the current state has already changed since when the reducer started:
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited