Java Code Examples for java.util.concurrent.CompletableFuture#thenCombineAsync()

The following examples show how to use java.util.concurrent.CompletableFuture#thenCombineAsync() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SupplyAsyncTest.java    From hellokoding-courses with MIT License 8 votes vote down vote up
@Test
public void thenCombineAsync() throws ExecutionException, InterruptedException {
    CompletableFuture<String> completableFuture1 = CompletableFuture.supplyAsync(() -> "Future");
    CompletableFuture<String> completableFuture2 = CompletableFuture.supplyAsync(() -> " is awesome!");

    CompletableFuture<String> combinedCompletableFuture = completableFuture1.thenCombineAsync(completableFuture2, (s1, s2) -> s1.concat(s2));

    assertThat(combinedCompletableFuture.get()).isEqualTo("Future is awesome!");
}
 
Example 2
Source File: XMLTextDocumentService.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
private static <R, M> CompletableFuture<R> computeModelAsync(CompletableFuture<M> loadModel,
		BiFunction<CancelChecker, M, R> code) {
	CompletableFuture<CancelChecker> start = new CompletableFuture<>();
	CompletableFuture<R> result = start.thenCombineAsync(loadModel, code);
	CancelChecker cancelIndicator = () -> {
		if (result.isCancelled())
			throw new CancellationException();
	};
	start.complete(cancelIndicator);
	return result;
}
 
Example 3
Source File: ExchangeApi.java    From exchange-core with Apache License 2.0 5 votes vote down vote up
private CompletableFuture<CommandResultCode> submitPersistCommandAsync(final ApiPersistState apiCommand) {

        final CompletableFuture<CommandResultCode> future1 = new CompletableFuture<>();
        final CompletableFuture<CommandResultCode> future2 = new CompletableFuture<>();

        publishPersistCmd(apiCommand, (seq1, seq2) -> {
            promises.put(seq1, cmd -> future1.complete(cmd.resultCode));
            promises.put(seq2, cmd -> future2.complete(cmd.resultCode));
        });

        return future1.thenCombineAsync(future2, CommandResultCode::mergeToFirstFailed);
    }
 
Example 4
Source File: CompletableFutureTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public <T,U,V> CompletableFuture<V> thenCombine
    (CompletableFuture<T> f,
     CompletionStage<? extends U> g,
     BiFunction<? super T,? super U,? extends V> a) {
    return f.thenCombineAsync(g, a);
}
 
Example 5
Source File: CompletableFutureTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public <T,U,V> CompletableFuture<V> thenCombine
    (CompletableFuture<T> f,
     CompletionStage<? extends U> g,
     BiFunction<? super T,? super U,? extends V> a) {
    return f.thenCombineAsync(g, a, new ThreadExecutor());
}
 
Example 6
Source File: CompletableFutureTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
public <T,U,V> CompletableFuture<V> thenCombine
    (CompletableFuture<T> f,
     CompletionStage<? extends U> g,
     BiFunction<? super T,? super U,? extends V> a) {
    return f.thenCombineAsync(g, a);
}
 
Example 7
Source File: CompletableFutureTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
public <T,U,V> CompletableFuture<V> thenCombine
    (CompletableFuture<T> f,
     CompletionStage<? extends U> g,
     BiFunction<? super T,? super U,? extends V> a) {
    return f.thenCombineAsync(g, a, new ThreadExecutor());
}