Retry function
Creates an Effect description that instructs the middleware to call
the function fn
with args
and namedArgs
as arguments.
In case of failure will try to make another call after
a duration
, if a number of attempts < maxTries
.
-
maxTries
is maximum calls count. -
duration
is length of a time window betweenfn
calls. -
fn
is a Generator function, or normal function which either returns a Promise as a result, or any other value. -
args
andnamedArgs
are values to be passed as arguments tofn
Example
In the following example, we create a basic task RetrySaga
. We use retry
to try to
fetch our API 3 times with 10 second interval. If request
fails first time than retry
will call request
one more time while calls count less than 3.,
import 'package:redux_saga/redux_saga.dart';
import 'Api.dart';
//...
retrySaga(data) sync* {
yield Try(() sync* {
var response = Result();
yield Retry(
request,
args: [data],
maxTries: 3,
duration: Duration(seconds: 10),
result: response,
);
yield Put(RequestSuccess(payload: response.value));
}, Catch: (e, s) sync* {
yield Put(RequestFail(payload: e));
});
}
Note that, retry
is a high-level API built using Delay and Call.
Implementation
Call Retry(Function fn,
{List<dynamic>? args,
Map<Symbol, dynamic>? namedArgs,
Function? Catch,
Function? Finally,
int? maxTries,
Duration? duration,
String? name,
Result? result}) {
return Call(_Retry,
args: <dynamic>[fn],
namedArgs: <Symbol, dynamic>{
#args: args,
#namedArgs: namedArgs,
#maxTries: maxTries,
#duration: duration,
#name: name,
#result: result
},
Catch: Catch,
Finally: Finally);
}