private void startRetry()

in src/main/java/com/spotify/futures/AsyncRetrier.java [90:121]


  private <T> void startRetry(final SettableFuture<T> future,
                              final Supplier<ListenableFuture<T>> code,
                              final int retries,
                              final long delay,
                              final TimeUnit timeUnit,
                              final Predicate<T> retryCondition) {

    ListenableFuture<T> codeFuture;
    try {
      codeFuture = code.get();
    } catch (Exception e) {
      handleFailure(future, code, retries, delay, timeUnit, retryCondition, e);
      return;
    }

    Futures.addCallback(codeFuture, new FutureCallback<T>() {
      @Override
      public void onSuccess(T result) {
        if (retryCondition.apply(result)) {
          future.set(result);
        } else {
          RuntimeException exception = new RuntimeException("Failed retry condition");
          handleFailure(future, code, retries, delay, timeUnit, retryCondition, exception);
        }
      }

      @Override
      public void onFailure(Throwable t) {
        handleFailure(future, code, retries, delay, timeUnit, retryCondition, t);
      }
    }, MoreExecutors.directExecutor());
  }