public static R retryWithResult()

in src/main/java/com/uber/cadence/internal/common/RpcRetryer.java [122:160]


  public static <R, T extends Throwable> R retryWithResult(
      RetryOptions options, RetryableFunc<R, T> r) throws T {
    int attempt = 0;
    long startTime = System.currentTimeMillis();
    BackoffThrottler throttler =
        new BackoffThrottler(
            options.getInitialInterval(),
            options.getMaximumInterval(),
            options.getBackoffCoefficient());
    do {
      try {
        attempt++;
        throttler.throttle();
        R result = r.apply();
        throttler.success();
        return result;
      } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new CancellationException();
      } catch (Exception e) {
        throttler.failure();
        if (options.getDoNotRetry() != null) {
          for (Class<?> exceptionToNotRetry : options.getDoNotRetry()) {
            if (exceptionToNotRetry.isAssignableFrom(e.getClass())) {
              rethrow(e);
            }
          }
        }
        long elapsed = System.currentTimeMillis() - startTime;
        int maxAttempts = options.getMaximumAttempts();
        Duration expiration = options.getExpiration();
        if ((maxAttempts > 0 && attempt >= maxAttempts)
            || (expiration != null && elapsed >= expiration.toMillis())) {
          rethrow(e);
        }
        log.warn("Retrying after failure", e);
      }
    } while (true);
  }