@Test public void or_completeNormally() throws Exception { SafeFuture<Integer> fut0 = new SafeFuture<>(); SafeFuture<Integer> fut1 = new SafeFuture<>(); assertThat(hasDependents(fut0)).isFalse(); SafeFuture<Integer> orFut = fut0.or(fut1); assertThat(hasDependents(fut0)).isTrue(); assertThat(hasDependents(fut1)).isTrue(); fut0.complete(12); assertThat(hasDependents(fut0)).isFalse(); assertThat(hasDependents(fut1)).isFalse(); assertThat(orFut.get()).isEqualTo(12); }
@SafeVarargs @SuppressWarnings("unchecked") public final SafeFuture<T> or(SafeFuture<T>... others) { SafeFuture<T>[] futures = Arrays.copyOf(others, others.length + 1); futures[others.length] = this; return anyOf(futures).thenApply(o -> (T) o); }
SafeFuture extends CompletableFuture<T> { @SafeVarargs @SuppressWarnings("unchecked") public final SafeFuture<T> or(SafeFuture<T>... others) { SafeFuture<T>[] futures = Arrays.copyOf(others, others.length + 1); futures[others.length] = this; return anyOf(futures).thenApply(o -> (T) o); } }
SafeFuture extends CompletableFuture<T> { @SafeVarargs @SuppressWarnings("unchecked") public final SafeFuture<T> or(SafeFuture<T>... others) { SafeFuture<T>[] futures = Arrays.copyOf(others, others.length + 1); futures[others.length] = this; return anyOf(futures).thenApply(o -> (T) o); }  }
SafeFuture extends CompletableFuture<T> { @SafeVarargs @SuppressWarnings("unchecked") public final SafeFuture<T> or(SafeFuture<T>... others) { SafeFuture<T>[] futures = Arrays.copyOf(others, others.length + 1); futures[others.length] = this; return anyOf(futures).thenApply(o -> (T) o); }  static void reportExceptions(final CompletionStage<?> future); static Consumer<T> reportExceptions(
      final Function<T, X> action); static SafeFuture<U> completedFuture(U value); static SafeFuture<U> failedFuture(Throwable ex); static SafeFuture<U> of(final CompletionStage<U> stage); static SafeFuture<U> of(final ExceptionThrowingFutureSupplier<U> futureSupplier); static SafeFuture<U> of(final ExceptionThrowingSupplier<U> supplier); static SafeFuture<U> ofComposed(
      final ExceptionThrowingSupplier<CompletionStage<U>> futureSupplier); static SafeFuture<Void> notInterrupted(Interruptor... interruptors); static Interruptor createInterruptor(
      CompletableFuture<?> interruptFuture, Supplier<Exception> exceptionSupplier); static SafeFuture<Void> fromRunnable(final ExceptionThrowingRunnable action); static SafeFuture<Void> allOf(final SafeFuture<?>... futures); @SuppressWarnings("FutureReturnValueIgnored") static void addSuppressedErrors(
      final Throwable completionException, final SafeFuture<?>[] futures); static SafeFuture<Void> allOfFailFast(final SafeFuture<?>... futures); static SafeFuture<Object> anyOf(final SafeFuture<?>... futures); @Override SafeFuture<U> newIncompleteFuture(); void reportExceptions(); void finish(final Runnable onSuccess, final Consumer<Throwable> onError); void propagateTo(final SafeFuture<T> target); void propagateToAsync(final SafeFuture<T> target, final AsyncRunner asyncRunner); void propagateExceptionTo(final SafeFuture<?> target); void always(final Runnable onFinished); SafeFuture<T> alwaysRun(final Runnable action); void finish(final Consumer<T> onSuccess, final Consumer<Throwable> onError); void finish(final Consumer<Throwable> onError); void finishAsync(final Consumer<Throwable> onError, final Executor executor); void finishAsync(
      final Runnable onSuccess, final Consumer<Throwable> onError, final Executor executor); void finishAsync(
      final Consumer<T> onSuccess, final Consumer<Throwable> onError, final Executor executor); @SuppressWarnings({"FutureReturnValueIgnored", "MissingOverride"}) SafeFuture<T> exceptionallyCompose(
      final Function<Throwable, ? extends CompletionStage<T>> errorHandler); SafeFuture<T> catchAndRethrow(final Consumer<Throwable> onError); static SafeFuture<U> supplyAsync(final Supplier<U> supplier); @SuppressWarnings("unchecked") @Override SafeFuture<U> thenApply(final Function<? super T, ? extends U> fn); SafeFuture<U> thenApplyChecked(final ExceptionThrowingFunction<T, U> function); SafeFuture<T> thenPeek(Consumer<T> fn); @Override SafeFuture<Void> thenRun(final Runnable action); @Override SafeFuture<Void> thenRunAsync(final Runnable action, final Executor executor); @Override SafeFuture<Void> thenAccept(final Consumer<? super T> action); @Override SafeFuture<Void> thenAcceptAsync(
      final Consumer<? super T> action, final Executor executor); @SuppressWarnings("unchecked") @Override SafeFuture<V> thenCombine(
      final CompletionStage<? extends U> other,
      final BiFunction<? super T, ? super U, ? extends V> fn); @Override SafeFuture<U> thenCompose(final Function<? super T, ? extends CompletionStage<U>> fn); @Override SafeFuture<U> thenComposeAsync(
      final Function<? super T, ? extends CompletionStage<U>> fn, final Executor executor); @Override SafeFuture<T> exceptionally(final Function<Throwable, ? extends T> fn); @SuppressWarnings("unchecked") @Override SafeFuture<U> handle(final BiFunction<? super T, Throwable, ? extends U> fn); @SuppressWarnings("unchecked") @Override SafeFuture<U> handleAsync(
      final BiFunction<? super T, Throwable, ? extends U> fn, final Executor executor); @SuppressWarnings({"FutureReturnValueIgnored"}) SafeFuture<U> handleComposed(
      final BiFunction<? super T, Throwable, CompletionStage<U>> fn); @Override SafeFuture<T> whenComplete(final BiConsumer<? super T, ? super Throwable> action); @Override SafeFuture<T> orTimeout(final long timeout, final TimeUnit unit); SafeFuture<T> whenException(final Consumer<Throwable> action); SafeFuture<T> thenWaitFor(Function<T, CompletionStage<?>> waitForStage); @SafeVarargs @SuppressWarnings("unchecked") final SafeFuture<T> or(SafeFuture<T>... others); @SuppressWarnings("FutureReturnValueIgnored") SafeFuture<T> orInterrupt(Interruptor... interruptors); }
SafeFuture extends CompletableFuture<T> { @SafeVarargs @SuppressWarnings("unchecked") public final SafeFuture<T> or(SafeFuture<T>... others) { SafeFuture<T>[] futures = Arrays.copyOf(others, others.length + 1); futures[others.length] = this; return anyOf(futures).thenApply(o -> (T) o); }  static void reportExceptions(final CompletionStage<?> future); static Consumer<T> reportExceptions(
      final Function<T, X> action); static SafeFuture<U> completedFuture(U value); static SafeFuture<U> failedFuture(Throwable ex); static SafeFuture<U> of(final CompletionStage<U> stage); static SafeFuture<U> of(final ExceptionThrowingFutureSupplier<U> futureSupplier); static SafeFuture<U> of(final ExceptionThrowingSupplier<U> supplier); static SafeFuture<U> ofComposed(
      final ExceptionThrowingSupplier<CompletionStage<U>> futureSupplier); static SafeFuture<Void> notInterrupted(Interruptor... interruptors); static Interruptor createInterruptor(
      CompletableFuture<?> interruptFuture, Supplier<Exception> exceptionSupplier); static SafeFuture<Void> fromRunnable(final ExceptionThrowingRunnable action); static SafeFuture<Void> allOf(final SafeFuture<?>... futures); @SuppressWarnings("FutureReturnValueIgnored") static void addSuppressedErrors(
      final Throwable completionException, final SafeFuture<?>[] futures); static SafeFuture<Void> allOfFailFast(final SafeFuture<?>... futures); static SafeFuture<Object> anyOf(final SafeFuture<?>... futures); @Override SafeFuture<U> newIncompleteFuture(); void reportExceptions(); void finish(final Runnable onSuccess, final Consumer<Throwable> onError); void propagateTo(final SafeFuture<T> target); void propagateToAsync(final SafeFuture<T> target, final AsyncRunner asyncRunner); void propagateExceptionTo(final SafeFuture<?> target); void always(final Runnable onFinished); SafeFuture<T> alwaysRun(final Runnable action); void finish(final Consumer<T> onSuccess, final Consumer<Throwable> onError); void finish(final Consumer<Throwable> onError); void finishAsync(final Consumer<Throwable> onError, final Executor executor); void finishAsync(
      final Runnable onSuccess, final Consumer<Throwable> onError, final Executor executor); void finishAsync(
      final Consumer<T> onSuccess, final Consumer<Throwable> onError, final Executor executor); @SuppressWarnings({"FutureReturnValueIgnored", "MissingOverride"}) SafeFuture<T> exceptionallyCompose(
      final Function<Throwable, ? extends CompletionStage<T>> errorHandler); SafeFuture<T> catchAndRethrow(final Consumer<Throwable> onError); static SafeFuture<U> supplyAsync(final Supplier<U> supplier); @SuppressWarnings("unchecked") @Override SafeFuture<U> thenApply(final Function<? super T, ? extends U> fn); SafeFuture<U> thenApplyChecked(final ExceptionThrowingFunction<T, U> function); SafeFuture<T> thenPeek(Consumer<T> fn); @Override SafeFuture<Void> thenRun(final Runnable action); @Override SafeFuture<Void> thenRunAsync(final Runnable action, final Executor executor); @Override SafeFuture<Void> thenAccept(final Consumer<? super T> action); @Override SafeFuture<Void> thenAcceptAsync(
      final Consumer<? super T> action, final Executor executor); @SuppressWarnings("unchecked") @Override SafeFuture<V> thenCombine(
      final CompletionStage<? extends U> other,
      final BiFunction<? super T, ? super U, ? extends V> fn); @Override SafeFuture<U> thenCompose(final Function<? super T, ? extends CompletionStage<U>> fn); @Override SafeFuture<U> thenComposeAsync(
      final Function<? super T, ? extends CompletionStage<U>> fn, final Executor executor); @Override SafeFuture<T> exceptionally(final Function<Throwable, ? extends T> fn); @SuppressWarnings("unchecked") @Override SafeFuture<U> handle(final BiFunction<? super T, Throwable, ? extends U> fn); @SuppressWarnings("unchecked") @Override SafeFuture<U> handleAsync(
      final BiFunction<? super T, Throwable, ? extends U> fn, final Executor executor); @SuppressWarnings({"FutureReturnValueIgnored"}) SafeFuture<U> handleComposed(
      final BiFunction<? super T, Throwable, CompletionStage<U>> fn); @Override SafeFuture<T> whenComplete(final BiConsumer<? super T, ? super Throwable> action); @Override SafeFuture<T> orTimeout(final long timeout, final TimeUnit unit); SafeFuture<T> whenException(final Consumer<Throwable> action); SafeFuture<T> thenWaitFor(Function<T, CompletionStage<?>> waitForStage); @SafeVarargs @SuppressWarnings("unchecked") final SafeFuture<T> or(SafeFuture<T>... others); @SuppressWarnings("FutureReturnValueIgnored") SafeFuture<T> orInterrupt(Interruptor... interruptors); static SafeFuture<Void> COMPLETE; }