call method
Implementation
Future<T> call() async {
var attempt = 0;
while (true) {
attempt++; // first invocation is the first attempt.
try {
return await func();
} catch (error) {
final attemptLimitReached = attempt >= maxAttempts;
if (attemptLimitReached) rethrow;
final shouldRetry = await retryIf?.call(error, attempt);
if (shouldRetry == false) rethrow;
}
// sleep for a delay.
await Future.delayed(_getSleepDuration(attempt));
}
}