本文整理匯總了Java中java.util.concurrent.CompletableFuture.thenCombine方法的典型用法代碼示例。如果您正苦於以下問題:Java CompletableFuture.thenCombine方法的具體用法?Java CompletableFuture.thenCombine怎麽用?Java CompletableFuture.thenCombine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.concurrent.CompletableFuture
的用法示例。
在下文中一共展示了CompletableFuture.thenCombine方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sort
import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
public static void sort(int[] array, int from, int to) {
int size = to - from;
if (size < cutoff) Arrays.sort(array, from, to);
else {
CompletableFuture<int[]> parsort1 = null; // TODO implement me
CompletableFuture<int[]> parsort2 = null; // TODO implement me
CompletableFuture<int[]> parsort = parsort1.
thenCombine(parsort2, (xs1, xs2) -> {
int[] result = new int[xs1.length + xs2.length];
// TODO implement me
return result;
});
parsort.whenComplete((result, throwable) -> {}); // TODO implement me
parsort.join();
}
}
示例2: combine
import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
private CompletableFuture<ResultData> combine(CompletableFuture<ResultData> future, CacheResult result) {
return future.thenCombine(result.future(), (d1, d2) -> {
if (d1 == null) {
return d2;
}
if (d1.getResultCode() != d2.getResultCode()) {
return new ResultData(CacheResultCode.PART_SUCCESS, null, null);
}
return d1;
});
}
示例3:
import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
public <T,U,V> CompletableFuture<V> thenCombine
(CompletableFuture<T> f,
CompletionStage<? extends U> g,
BiFunction<? super T,? super U,? extends V> a) {
return f.thenCombine(g, a);
}
示例4: testSignalAndWaitFromTwo
import java.util.concurrent.CompletableFuture; //導入方法依賴的package包/類
@Test
public void testSignalAndWaitFromTwo() {
AsyncCountdownEvent evt = new AsyncCountdownEvent(2);
CompletableFuture<Void> first = evt.signalAndWaitAsync();
Assert.assertFalse(first.isDone());
CompletableFuture<Void> second = evt.signalAndWaitAsync();
CompletableFuture<Void> future = first.thenCombine(second, (a, b) -> null);
future.join();
}