@Override public <U, V> DefaultConnectionFuture<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn, Executor executor) { return adopt(delegate.thenCombineAsync(other, fn, executor)); }
@Override public <U, V> DefaultConnectionFuture<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) { return adopt(delegate.thenCombineAsync(other, fn)); }
@Override public <U, V> CompletableFuture<V> thenCombineAsync( CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn, Executor executor) { return wrap(super.thenCombineAsync(other, fn, executor)); }
@Override public <U, V> CompletableFuture<V> thenCombineAsync( CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) { return wrap(super.thenCombineAsync(other, fn)); }
@Override public <U, V> Task<V> thenCombineAsync(CompletionStage<? extends U> completionStage, BiFunction<? super T, ? super U, ? extends V> biFunction) { final BiFunction<? super T, ? super U, ? extends V> wrap = TaskContext.wrap(biFunction); return Task.from(super.thenCombineAsync(completionStage, wrap)); }
@Override public <U,V> CompletableFuture<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn) { return ctx.makeContextAware(super.thenCombineAsync(other, ctx.makeContextAware(fn))); }
@Override public <U,V> CompletableFuture<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn, Executor executor) { return ctx.makeContextAware(super.thenCombineAsync(other, ctx.makeContextAware(fn), executor)); }
@Override public <U, V> Task<V> thenCombineAsync(CompletionStage<? extends U> completionStage, BiFunction<? super T, ? super U, ? extends V> biFunction, Executor executor) { final BiFunction<? super T, ? super U, ? extends V> wrap = TaskContext.wrap(biFunction); return Task.from(super.thenCombineAsync(completionStage, wrap, executor)); }
@Override public <U, V> CompletableFuture<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) { return wrap(orderedFuture().thenCombineAsync(other, fn)); }
@Override public <U, V> CompletableFuture<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn, Executor executor) { return wrap(orderedFuture().thenCombineAsync(other, fn, executor)); }
@Override public <U, V> Task<V> thenCombine(CompletionStage<? extends U> completionStage, BiFunction<? super T, ? super U, ? extends V> biFunction) { final BiFunction<? super T, ? super U, ? extends V> wrap = TaskContext.wrap(biFunction); if (defaultExecutor != null) { return Task.from(super.thenCombineAsync(completionStage, wrap, defaultExecutor)); } return Task.from(super.thenCombine(completionStage, wrap)); }
@Test @SuppressWarnings("unchecked") public void introFutureHell() { CompletableFuture<List<String>> ids = ifhIds(); // <1> CompletableFuture<List<String>> result = ids.thenComposeAsync(l -> { // <2> Stream<CompletableFuture<String>> zip = l.stream().map(i -> { // <3> CompletableFuture<String> nameTask = ifhName(i); // <4> CompletableFuture<Integer> statTask = ifhStat(i); // <5> return nameTask.thenCombineAsync(statTask, (name, stat) -> "Name " + name + " has stats " + stat); // <6> }); List<CompletableFuture<String>> combinationList = zip.collect(Collectors.toList()); // <7> CompletableFuture<String>[] combinationArray = combinationList.toArray(new CompletableFuture[combinationList.size()]); CompletableFuture<Void> allDone = CompletableFuture.allOf(combinationArray); // <8> return allDone.thenApply(v -> combinationList.stream() .map(CompletableFuture::join) // <9> .collect(Collectors.toList())); }); List<String> results = result.join(); // <10> assertThat(results).contains( "Name NameJoe has stats 103", "Name NameBart has stats 104", "Name NameHenry has stats 105", "Name NameNicole has stats 106", "Name NameABSLAJNFOAJNFOANFANSF has stats 121"); }
public <U, V> VertxCompletableFuture<V> thenCombineAsync( CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn, Executor executor) { return new VertxCompletableFuture<>(context, super.thenCombineAsync(other, fn, executor)); }
@Override public <U, V> VertxCompletableFuture<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) { return new VertxCompletableFuture<>(context, super.thenCombineAsync(other, fn, executor)); }
CompletableFuture<String> firstFuture = firstMethod(); CompletableFuture<String> secondFuture = secondMethod(); CompletableFuture<String> thirdFuture = thirdMethod(); CompletableFuture<List<String>> allCompleted = firstFuture .thenCombineAsync(secondFuture, (first, second) -> listOf(first, second)) .thenCombineAsync(thirdFuture, (list, third) -> { list.add(third); return list; });
@Override public <U, V> CompletableFuture<V> thenCombineAsync( CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) { return wrap(super.thenCombineAsync(other, fn)); }
@Override public <U, V> VertxCompletableFuture<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) { return new VertxCompletableFuture<>(context, super.thenCombineAsync(other, fn, executor)); }
public <U, V> VertxCompletableFuture<V> thenCombineAsync( CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn, Executor executor) { return new VertxCompletableFuture<>(context, super.thenCombineAsync(other, fn, executor)); }
@Override public <U, V> VertxCompletableFuture<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) { return new VertxCompletableFuture<>(context, super.thenCombineAsync(other, fn, executor)); }
@Override public <U, V> VertxCompletableFuture<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) { return new VertxCompletableFuture<>(context, super.thenCombineAsync(other, fn, executor)); }