当前位置: 首页>>代码示例>>Java>>正文


Java CompletionStage.thenApplyAsync方法代码示例

本文整理汇总了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));
}
 
开发者ID:soabase,项目名称:soabase-stages,代码行数:14,代码来源:Aborted.java

示例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());
}
 
开发者ID:soabase,项目名称:soabase-stages,代码行数:14,代码来源:Aborted.java


注:本文中的java.util.concurrent.CompletionStage.thenApplyAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。