本文整理汇总了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));
}}
示例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()))
);
}
示例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));
}
示例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)));
}