@Override public <U, V> DefaultConnectionFuture<V> thenCombine(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) { return adopt(delegate.thenCombine(other, fn)); }
@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)); }
@Override public <U, V> CompletableFuture<V> thenCombine( CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) { return wrap(super.thenCombine(other, fn)); }
public void isLargerGroup(String artistName, String otherArtistName, Consumer<Boolean> handler) { CompletableFuture<Long> otherArtistMemberCount = CompletableFuture.supplyAsync(() -> getNumberOfMembers(otherArtistName)); CompletableFuture<Long> artistMemberCount = CompletableFuture.completedFuture(getNumberOfMembers(artistName)); artistMemberCount.thenCombine(otherArtistMemberCount, (count, otherCount) -> count > otherCount) .thenAccept(handler::accept); }
@Override public <U,V> CompletableFuture<V> thenCombine(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn) { return ctx.makeContextAware(super.thenCombine(other, ctx.makeContextAware(fn))); }
@Override public <U, V> CompletableFuture<V> thenCombine(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) { return wrap(orderedFuture().thenCombine(other, fn)); }
public Album lookupByName(String albumName) { CompletableFuture<List<Artist>> artistLookup = loginTo("artist") .thenCompose(artistLogin -> lookupArtists(albumName, artistLogin)); // <1> return loginTo("track") .thenCompose(trackLogin -> lookupTracks(albumName, trackLogin)) // <2> .thenCombine(artistLookup, (tracks, artists) -> new Album(albumName, tracks, artists)) // <3> .join(); // <4> } // END lookupByName
CompletableFuture<Integer> mappedAndCombined = randomNum.thenCombine(anotherNum, (num1, num2) -> num1 + num2);
.thenCombine(jobGraphFileFuture, (ignored, jobGraphFile) -> jobGraphFile) .thenAccept(jobGraphFile -> { try {
private CompletableFuture<ResultData> combine(CompletableFuture<ResultData> future, CacheResult result) { return future.thenCombine(result.future(), (d1, d2) -> { if (d1 == null) { return d2; } if (d1.getResultCode() != d2.getResultCode()) { return new ResultData(CacheResultCode.PART_SUCCESS, null, null); } return d1; }); }
CompletableFuture<JobGraph> jarUploadFuture = jobGraphFuture.thenCombine(blobServerPortFuture, (jobGraph, blobServerPort) -> { final InetSocketAddress address = new InetSocketAddress(gateway.getHostname(), blobServerPort); try { .thenCombine(jarUploadFuture, (ack, jobGraph) -> new JarRunResponseBody(jobGraph.getJobID())) .exceptionally(throwable -> { throw new CompletionException(new RestHandlerException(
.thenCombine(dataStatAclNodeCompletableFuture, combineEnsureNodeAndTransferNodeStage) .thenCompose(transmitNodeStage); }).collect(Collectors.toList());
(InvocationOnMock invocation) -> { Container container = (Container) invocation.getArguments()[0]; resourceManagerFuture.thenCombine(leaderGatewayFuture, (resourceManagerGateway, leaderGateway) -> { resourceManagerGateway.tell(
/** * Combine the given CompletionStages into a single {@link CompletionStage} for the list of results. * * The sequencing operations are performed in the default ExecutionContext. * * @param promises The CompletionStages to combine * @param <A> the type of the completion's result. * @return A single CompletionStage whose methods act on the list of redeemed CompletionStages */ static <A> CompletionStage<List<A>> sequence(Iterable<? extends CompletionStage<A>> promises) { CompletableFuture<List<A>> result = CompletableFuture.completedFuture(new ArrayList<>()); for (CompletionStage<A> promise: promises) { result = result.thenCombine(promise, (list, a) -> { list.add(a); return list; }); } return result; }
@Override public <U, V> VertxCompletableFuture<V> thenCombine(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) { return new VertxCompletableFuture<>(context, super.thenCombine(other, fn)); }
public static void main(String[] args) { try { String s = CompletableFuture.supplyAsync(() -> 23333) .thenCombine(CompletableFuture.supplyAsync( () -> "8898" ), (a, b) -> { System.out.println("a =" + a); System.out.println("b =" + b); return a + b; }) .get(); System.out.println(s); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } } }
public static <T> CompletableFuture<T> merge(List<CompletableFuture<T>> futures, BiFunction<T,T,T> mergeFunc, Supplier<T> nothing) { if (futures.size() == 0) { return CompletableFuture.completedFuture(nothing.get()); } while (futures.size() > 1) { ArrayList<CompletableFuture<T>> mergedFutures = new ArrayList<>(futures.size() / 2); for (int i = 0; i < futures.size(); i += 2) { if (i + 1 == futures.size()) { mergedFutures.add(futures.get(i)); } else { mergedFutures.add(futures.get(i).thenCombine(futures.get(i + 1), mergeFunc)); } } futures = mergedFutures; } return futures.get(0); }
public static <T> CompletableFuture<ReactiveSeq<T>> sequence(ReactiveSeq<? extends CompletableFuture<T>> stream) { CompletableFuture<ReactiveSeq<T>> identity = CompletableFuture.completedFuture(ReactiveSeq.empty()); BiFunction<CompletableFuture<ReactiveSeq<T>>,CompletableFuture<T>,CompletableFuture<ReactiveSeq<T>>> combineToStream = (acc,next) ->acc.thenCombine(next,(a,b)->a.append(b)); BinaryOperator<CompletableFuture<ReactiveSeq<T>>> combineStreams = (a,b)-> a.thenCombine(b,(z1,z2)->z1.appendStream(z2)); return stream.reduce(identity,combineToStream,combineStreams); } public static <T,R> CompletableFuture<ReactiveSeq<R>> traverse(Function<? super T,? extends R> fn,ReactiveSeq<CompletableFuture<T>> stream) {
@Override public <T2, R> Future<R> zip(final Iterable<? extends T2> app, final BiFunction<? super T, ? super T2, ? extends R> fn) { return Future.of(future.thenCombine(Future.fromIterable(app).getFuture(), fn)); }
@Override public <T2, R> Future<R> zip(final BiFunction<? super T, ? super T2, ? extends R> fn, final Publisher<? extends T2> app) { return Future.of(future.thenCombine(Future.fromPublisher(app).getFuture(), fn)); }