withRetry<T> function
Future<T>
withRetry<
T>( - FutureOr<T> action(), {
- int retryTimes = 3,
- int retryIntervalMills = 500,
})
Implementation
Future<T> withRetry<T>(
FutureOr<T> Function() action, {
int retryTimes = 3,
int retryIntervalMills = 500,
}) async {
assert(retryTimes >= 0);
assert(retryIntervalMills >= 0);
int times = 0;
while (true) {
try {
return await action();
} catch (e) {
times++;
if (times >= retryTimes) {
rethrow;
}
await Future.delayed(Duration(milliseconds: times * retryIntervalMills));
}
}
}