当前位置: 首页>>代码示例>>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;未经允许,请勿转载。