本文整理匯總了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)));
}