當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。