本文整理汇总了Java中java.util.concurrent.CompletableFuture.handleAsync方法的典型用法代码示例。如果您正苦于以下问题:Java CompletableFuture.handleAsync方法的具体用法?Java CompletableFuture.handleAsync怎么用?Java CompletableFuture.handleAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.CompletableFuture
的用法示例。
在下文中一共展示了CompletableFuture.handleAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyOnExecutor
import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
private <R, T> CompletableFuture<R> applyOnExecutor(CompletableFuture<T> eventLoopFuture, Function<T, R> mapper) {
if (executor == SmtpSessionFactoryConfig.DIRECT_EXECUTOR) {
return eventLoopFuture.thenApply(mapper);
}
// use handleAsync to ensure exceptions and other callbacks are completed on the ExecutorService thread
return eventLoopFuture.handleAsync((rs, e) -> {
if (e != null) {
throw Throwables.propagate(e);
}
return mapper.apply(rs);
}, executor);
}
示例2: ThreadExecutor
import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
public <T,U> CompletableFuture<U> handle
(CompletableFuture<T> f,
BiFunction<? super T,Throwable,? extends U> a) {
return f.handleAsync(a, new ThreadExecutor());
}
示例3:
import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
public <T,U> CompletableFuture<U> handle
(CompletableFuture<T> f,
BiFunction<? super T,Throwable,? extends U> a) {
return f.handleAsync(a);
}