@Test public void shouldExecuteAllFunctionsFromMappings() throws Exception { CompletableFuture<String> future = CompletableFuture.completedFuture("SampleText"); CompletableFuture<Stream<Integer>> actualFuture = future.thenCompose( fanOut(ImmutableList.of( text -> 1, text -> 2, text -> 4 )) ); CompletableFuture<Integer> actualSum = actualFuture.thenApply( stream -> stream.reduce((a, b) -> a + b).orElse(-1) ); assertThat(actualSum.get(), is(equalTo(7))); }
static <F, T> Function<F, CompletableFuture<Stream<T>>> fanOut(Collection<Function<F, T>> mappings) { return fanOut(mappings, ForkJoinPool.commonPool()); }
CompletableFutures { static <F, T> Function<F, CompletableFuture<Stream<T>>> fanOut(Collection<Function<F, T>> mappings) { return fanOut(mappings, ForkJoinPool.commonPool()); } }
CompletableFutures { static <F, T> Function<F, CompletableFuture<Stream<T>>> fanOut(Collection<Function<F, T>> mappings) { return fanOut(mappings, ForkJoinPool.commonPool()); } private  CompletableFutures(); }
CompletableFutures { static <F, T> Function<F, CompletableFuture<Stream<T>>> fanOut(Collection<Function<F, T>> mappings) { return fanOut(mappings, ForkJoinPool.commonPool()); } private  CompletableFutures(); static BinaryOperator<CompletableFuture<T>> combineUsing(BiFunction<T, T, T> combiningFunction); static BinaryOperator<CompletableFuture<T>> combineUsing(BiFunction<T, T, T> combiningFunction, ExecutorService executorService); }
CompletableFutures { static <F, T> Function<F, CompletableFuture<Stream<T>>> fanOut(Collection<Function<F, T>> mappings) { return fanOut(mappings, ForkJoinPool.commonPool()); } private  CompletableFutures(); static BinaryOperator<CompletableFuture<T>> combineUsing(BiFunction<T, T, T> combiningFunction); static BinaryOperator<CompletableFuture<T>> combineUsing(BiFunction<T, T, T> combiningFunction, ExecutorService executorService);  }