@Test(timeout = 1000) public void allInSequenceOnlyFirstOfTwoFailing(final TestContext testContext) { final Async async = testContext.async(); FutureUtils.allInSequence(Arrays.<Supplier<CompletableFuture<Boolean>>>asList( indexedFutureSupplier(1, false), indexedFutureSupplier(2, true)) .stream()) .thenAccept(b -> executionContext.runOnContext(() -> { assertThat(b, is(true)); assertThat(endStep.get(), is(2)); async.complete(); })); }
public static CompletableFuture<Boolean> allInSequence(final Stream<Supplier<CompletableFuture<Boolean>>> futureSuppliers) { return futureSuppliers.reduce(completedFuture(Boolean.FALSE), (f, a) -> f.thenCompose(b1 -> a.get().thenCompose(b2 -> CompletableFuture.completedFuture(b1 || b2))), (bf1, bf2) -> bf1.thenCompose(b1 -> bf2.thenCompose(b2 -> CompletableFuture.completedFuture(b1 || b2)))); }
FutureUtils { public static CompletableFuture<Boolean> allInSequence(final Stream<Supplier<CompletableFuture<Boolean>>> futureSuppliers) { return futureSuppliers.reduce(completedFuture(Boolean.FALSE), (f, a) -> f.thenCompose(b1 -> a.get().thenCompose(b2 -> CompletableFuture.completedFuture(b1 || b2))), (bf1, bf2) -> bf1.thenCompose(b1 -> bf2.thenCompose(b2 -> CompletableFuture.completedFuture(b1 || b2)))); } }
FutureUtils { public static CompletableFuture<Boolean> allInSequence(final Stream<Supplier<CompletableFuture<Boolean>>> futureSuppliers) { return futureSuppliers.reduce(completedFuture(Boolean.FALSE), (f, a) -> f.thenCompose(b1 -> a.get().thenCompose(b2 -> CompletableFuture.completedFuture(b1 || b2))), (bf1, bf2) -> bf1.thenCompose(b1 -> bf2.thenCompose(b2 -> CompletableFuture.completedFuture(b1 || b2)))); }  }
FutureUtils { public static CompletableFuture<Boolean> allInSequence(final Stream<Supplier<CompletableFuture<Boolean>>> futureSuppliers) { return futureSuppliers.reduce(completedFuture(Boolean.FALSE), (f, a) -> f.thenCompose(b1 -> a.get().thenCompose(b2 -> CompletableFuture.completedFuture(b1 || b2))), (bf1, bf2) -> bf1.thenCompose(b1 -> bf2.thenCompose(b2 -> CompletableFuture.completedFuture(b1 || b2)))); }  static CompletableFuture<Void> allOf(Stream<CompletableFuture<T>> futures); static CompletableFuture<List<T>> combineFuturesToList(List<CompletableFuture<T>> futureList); static CompletableFuture<T> withFallback(final CompletableFuture<T> originalFuture,
                                                                          final Supplier<CompletableFuture<T>> fallbackFutureSupplier); static CompletableFuture<Boolean> allInSequence(final Stream<Supplier<CompletableFuture<Boolean>>> futureSuppliers); static CompletableFuture<Boolean> shortCircuitedFuture(final Stream<Supplier<CompletableFuture<Boolean>>> futureSuppliers,
                                                                  final Boolean fallbackOn); }
FutureUtils { public static CompletableFuture<Boolean> allInSequence(final Stream<Supplier<CompletableFuture<Boolean>>> futureSuppliers) { return futureSuppliers.reduce(completedFuture(Boolean.FALSE), (f, a) -> f.thenCompose(b1 -> a.get().thenCompose(b2 -> CompletableFuture.completedFuture(b1 || b2))), (bf1, bf2) -> bf1.thenCompose(b1 -> bf2.thenCompose(b2 -> CompletableFuture.completedFuture(b1 || b2)))); }  static CompletableFuture<Void> allOf(Stream<CompletableFuture<T>> futures); static CompletableFuture<List<T>> combineFuturesToList(List<CompletableFuture<T>> futureList); static CompletableFuture<T> withFallback(final CompletableFuture<T> originalFuture,
                                                                          final Supplier<CompletableFuture<T>> fallbackFutureSupplier); static CompletableFuture<Boolean> allInSequence(final Stream<Supplier<CompletableFuture<Boolean>>> futureSuppliers); static CompletableFuture<Boolean> shortCircuitedFuture(final Stream<Supplier<CompletableFuture<Boolean>>> futureSuppliers,
                                                                  final Boolean fallbackOn);  }