run<T> static method
Implementation
static Future<T> run<T>(
Future<T> Function() fn, {
required AutoPilotConfig cfg,
required String url,
}) async {
int attempt = 0;
while (true) {
try {
return await fn();
} catch (e) {
attempt++;
if (!_retryable(e) || attempt >= cfg.maxRetries) rethrow;
AutoPilotLogger.retry(attempt, cfg.maxRetries, url);
// exponential: 1s, 2s, 3s ...
await Future.delayed(cfg.retryDelay * attempt);
}
}
}