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