run<T> static method

Future<T> run<T>(
  1. Future<T> fn(), {
  2. required AutoPilotConfig cfg,
  3. required String url,
})

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.logRetry(attempt, cfg.maxRetries, url);
      // Exponential backoff: 1s, 2s, 3s ...
      await Future.delayed(cfg.retryDelay * attempt);
    }
  }
}