retryWithDelay<T> function
Retry a function with exponential backoff
Implementation
Future<T> retryWithDelay<T>(
Future<T> Function() fn, {
int maxRetries = 3,
int initialDelayMs = 1000,
double backoffMultiplier = 2.0,
}) async {
int attempt = 0;
int delayMs = initialDelayMs;
while (true) {
try {
return await fn();
} catch (e) {
attempt++;
if (attempt >= maxRetries) {
rethrow;
}
logDebug('Retry attempt $attempt after error: $e');
await delay(delayMs);
delayMs = (delayMs * backoffMultiplier).round();
}
}
}