retry method
Implementation
Future<T> retry({
int times = 3,
Duration delay = const Duration(seconds: 1),
bool Function(Object error)? retryIf,
}) async {
for (var i = 0; i < times; i++) {
try {
return await this;
} catch (e) {
final shouldRetry = retryIf?.call(e) ?? true;
if (i == times - 1 || !shouldRetry) rethrow;
await Future.delayed(delay);
}
}
return await this;
}