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