本文整理汇总了Java中java.util.concurrent.CompletionStage.thenApplyAsync方法的典型用法代码示例。如果您正苦于以下问题:Java CompletionStage.thenApplyAsync方法的具体用法?Java CompletionStage.thenApplyAsync怎么用?Java CompletionStage.thenApplyAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.CompletionStage
的用法示例。
在下文中一共展示了CompletionStage.thenApplyAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: whenSucceededAsync
import java.util.concurrent.CompletionStage; //导入方法依赖的package包/类
/**
* Return a new CompletionStage that calls the given handler iff the given stage
* completes successfully, executed using this stage's default asynchronous execution facility, with
* an {@link Optional} that is not empty.
*
* @param stage the stage to wrap
* @param handler success handler - called only when the given stage returns a non-empty Optional
* @return new CompletionStage
*/
public static <T, U> CompletionStage<Optional<U>> whenSucceededAsync(CompletionStage<Optional<T>> stage, Function<T, Optional<U>> handler)
{
return stage.thenApplyAsync(optional -> optional.flatMap(handler));
}
示例2: whenAbortedAsync
import java.util.concurrent.CompletionStage; //导入方法依赖的package包/类
/**
* Return a new CompletionStage that calls the given handler iff the given stage
* completes successfully, executed using this stage's default asynchronous execution facility, with
* an {@link Optional} that is empty.
*
* @param stage the stage to wrap
* @param handler success handler - called only when the given stage returns an empty Optional
* @return new CompletionStage
*/
public static <T, U> CompletionStage<Optional<U>> whenAbortedAsync(CompletionStage<Optional<T>> stage, Supplier<Optional<U>> handler)
{
return stage.thenApplyAsync(optional -> optional.isPresent() ? Optional.empty() : handler.get());
}