@Override public void accept(final V v, final Throwable throwable) { if (throwable != null) { if (throwable instanceof CancellationException) { cancel(false); } else { setException(unwrapThrowable(throwable)); } } else { set(v); } }
/** * Wrap a {@link CompletionStage} in a {@link ListenableFuture}. The returned future will * complete with the same result or failure as the original future. * * @param future The {@link CompletionStage} to wrap in a {@link ListenableFuture}. * @return A {@link ListenableFuture} that completes when the original future completes. */ public static <V> ListenableFuture<V> toListenableFuture( CompletionStage<V> future) { if (future instanceof ListenableToCompletableFutureWrapper) { return ((ListenableToCompletableFutureWrapper<V>) future).unwrap(); } return new CompletableToListenableFutureWrapper<>(future); }
/** * Wrap a {@link ListenableFuture} in a {@link CompletableFuture}. The returned future will * complete with the same result or failure as the original future. Completing the returned * future does not complete the original future. * * @param future The {@link ListenableFuture} to wrap in a {@link CompletableFuture}. * @return A {@link CompletableFuture} that completes when the original future completes. */ public static <V> CompletableFuture<V> toCompletableFuture( ListenableFuture<V> future) { if (future instanceof CompletableToListenableFutureWrapper) { return ((CompletableToListenableFutureWrapper<V>) future).unwrap(); } return new ListenableToCompletableFutureWrapper<>(future); }
@Override public void accept(V v, Throwable throwable) { if (throwable != null) { if (throwable instanceof CancellationException) { cancel(false); } else { setException(CompletableToListenableFutureWrapper.unwrapThrowable(throwable)); } } else { set(v); } } }