當前位置: 首頁>>代碼示例>>Java>>正文


Java CompletionStage.thenAccept方法代碼示例

本文整理匯總了Java中java.util.concurrent.CompletionStage.thenAccept方法的典型用法代碼示例。如果您正苦於以下問題:Java CompletionStage.thenAccept方法的具體用法?Java CompletionStage.thenAccept怎麽用?Java CompletionStage.thenAccept使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.concurrent.CompletionStage的用法示例。


在下文中一共展示了CompletionStage.thenAccept方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testMinimalCompletionStage_join_by_hand

import java.util.concurrent.CompletionStage; //導入方法依賴的package包/類
/**
 * Joining a minimal stage "by hand" works
 */
public void testMinimalCompletionStage_join_by_hand() {
    for (boolean createIncomplete : new boolean[] { true, false })
    for (Integer v1 : new Integer[] { 1, null })
{
    CompletableFuture<Integer> f = new CompletableFuture<>();
    CompletionStage<Integer> minimal = f.minimalCompletionStage();
    CompletableFuture<Integer> g = new CompletableFuture<>();
    if (!createIncomplete) assertTrue(f.complete(v1));
    minimal.thenAccept(x -> g.complete(x));
    if (createIncomplete) assertTrue(f.complete(v1));
    g.join();
    checkCompletedNormally(g, v1);
    checkCompletedNormally(f, v1);
    assertEquals(v1, join(minimal));
}}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:CompletableFutureTest.java

示例2: browse

import java.util.concurrent.CompletionStage; //導入方法依賴的package包/類
private void browse(final URI uri) {
    final CompletionStage<Try<Void>> browserOpeningResult = AwtUtils.asyncAwtCallbackWithRequirement(
        Desktop::getDesktop,
        desktop -> Try.run(() -> desktop.browse(uri))
    );

    browserOpeningResult.thenAccept(result ->
        result.onFailure(cause -> onException(cause, uri.toString()))
    );
}
 
開發者ID:Tristan971,項目名稱:EasyFXML,代碼行數:11,代碼來源:BrowserSupport.java

示例3: should_Build_a_really_really_simple_data_loader

import java.util.concurrent.CompletionStage; //導入方法依賴的package包/類
@Test
public void should_Build_a_really_really_simple_data_loader() {
    AtomicBoolean success = new AtomicBoolean();
    DataLoader<Integer, Integer> identityLoader = new DataLoader<>(keysAsValues());

    CompletionStage<Integer> future1 = identityLoader.load(1);

    future1.thenAccept(value -> {
        assertThat(value, equalTo(1));
        success.set(true);
    });
    identityLoader.dispatch();
    await().untilAtomic(success, is(true));
}
 
開發者ID:bbakerman,項目名稱:java-dataloader,代碼行數:15,代碼來源:DataLoaderTest.java

示例4: should_Support_loading_multiple_keys_in_one_call

import java.util.concurrent.CompletionStage; //導入方法依賴的package包/類
@Test
public void should_Support_loading_multiple_keys_in_one_call() {
    AtomicBoolean success = new AtomicBoolean();
    DataLoader<Integer, Integer> identityLoader = new DataLoader<>(keysAsValues());

    CompletionStage<List<Integer>> futureAll = identityLoader.loadMany(asList(1, 2));
    futureAll.thenAccept(promisedValues -> {
        assertThat(promisedValues.size(), is(2));
        success.set(true);
    });
    identityLoader.dispatch();
    await().untilAtomic(success, is(true));
    assertThat(futureAll.toCompletableFuture().join(), equalTo(asList(1, 2)));
}
 
開發者ID:bbakerman,項目名稱:java-dataloader,代碼行數:15,代碼來源:DataLoaderTest.java


注:本文中的java.util.concurrent.CompletionStage.thenAccept方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。