当前位置: 首页>>代码示例>>Java>>正文


Java CompletableFuture.completeAsync方法代码示例

本文整理汇总了Java中java.util.concurrent.CompletableFuture.completeAsync方法的典型用法代码示例。如果您正苦于以下问题:Java CompletableFuture.completeAsync方法的具体用法?Java CompletableFuture.completeAsync怎么用?Java CompletableFuture.completeAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.CompletableFuture的用法示例。


在下文中一共展示了CompletableFuture.completeAsync方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: completeResponse

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
@Override
void completeResponse(Response r) {
    HttpResponseImpl.logResponse(r);
    pushCF.complete(r); // not strictly required for push API
    // start reading the body using the obtained BodyProcessor
    CompletableFuture<Void> start = new MinimalFuture<>();
    start.thenCompose( v -> readBodyAsync(getPushHandler(), false, getExchange().executor()))
        .whenComplete((T body, Throwable t) -> {
            if (t != null) {
                responseCF.completeExceptionally(t);
            } else {
                HttpResponseImpl<T> response = new HttpResponseImpl<>(r.request, r, body, getExchange());
                responseCF.complete(response);
            }
        });
    start.completeAsync(() -> null, getExchange().executor());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:Stream.java

示例2: multiResponseAsync

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
CompletableFuture<U> multiResponseAsync() {
    CompletableFuture<Void> start = new MinimalFuture<>();
    CompletableFuture<HttpResponseImpl<T>> cf = responseAsync0(start);
    CompletableFuture<HttpResponse<T>> mainResponse =
            cf.thenApply((HttpResponseImpl<T> b) -> {
                  multiResponseHandler.onResponse(b);
                  return (HttpResponse<T>)b;
               });

    pushGroup.setMainResponse(mainResponse);
    // set up house-keeping related to multi-response
    mainResponse.thenAccept((r) -> {
        // All push promises received by now.
        pushGroup.noMorePushes(true);
    });
    CompletableFuture<U> res = multiResponseHandler.completion(pushGroup.groupResult(), pushGroup.pushesCF());
    start.completeAsync( () -> null, executor); // trigger execution
    return res;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:MultiExchange.java

示例3: supply

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
public static <U> CompletableFuture<U> supply(ExceptionalSupplier<U> supplier, Executor executor) {
    CompletableFuture<U> cf = new MinimalFuture<>();
    cf.completeAsync( () -> {
        try {
            return supplier.get();
        } catch (Throwable ex) {
            throw new CompletionException(ex);
        }
    }, executor);
    return cf;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:MinimalFuture.java

示例4: testCompleteAsync

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
/**
 * completeAsync completes with value of given supplier
 */
public void testCompleteAsync() {
    for (Integer v1 : new Integer[] { 1, null })
{
    CompletableFuture<Integer> f = new CompletableFuture<>();
    f.completeAsync(() -> v1);
    f.join();
    checkCompletedNormally(f, v1);
}}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:CompletableFutureTest.java

示例5: testCompleteAsync2

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
/**
 * completeAsync completes exceptionally if given supplier throws
 */
public void testCompleteAsync2() {
    CompletableFuture<Integer> f = new CompletableFuture<>();
    CFException ex = new CFException();
    f.completeAsync(() -> { throw ex; });
    try {
        f.join();
        shouldThrow();
    } catch (CompletionException success) {}
    checkCompletedWithWrappedException(f, ex);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:CompletableFutureTest.java

示例6: testCompleteAsync3

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
/**
 * completeAsync with given executor completes with value of given supplier
 */
public void testCompleteAsync3() {
    for (Integer v1 : new Integer[] { 1, null })
{
    CompletableFuture<Integer> f = new CompletableFuture<>();
    ThreadExecutor executor = new ThreadExecutor();
    f.completeAsync(() -> v1, executor);
    assertSame(v1, f.join());
    checkCompletedNormally(f, v1);
    assertEquals(1, executor.count.get());
}}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:CompletableFutureTest.java

示例7: testCompleteAsync4

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
/**
 * completeAsync with given executor completes exceptionally if
 * given supplier throws
 */
public void testCompleteAsync4() {
    CompletableFuture<Integer> f = new CompletableFuture<>();
    CFException ex = new CFException();
    ThreadExecutor executor = new ThreadExecutor();
    f.completeAsync(() -> { throw ex; }, executor);
    try {
        f.join();
        shouldThrow();
    } catch (CompletionException success) {}
    checkCompletedWithWrappedException(f, ex);
    assertEquals(1, executor.count.get());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:CompletableFutureTest.java

示例8: responseAsync

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
public CompletableFuture<HttpResponseImpl<T>> responseAsync() {
    CompletableFuture<Void> start = new MinimalFuture<>();
    CompletableFuture<HttpResponseImpl<T>> cf = responseAsync0(start);
    start.completeAsync( () -> null, executor); // trigger execution
    return cf;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:MultiExchange.java


注:本文中的java.util.concurrent.CompletableFuture.completeAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。