本文整理汇总了Java中java.util.concurrent.CompletionStage.thenApply方法的典型用法代码示例。如果您正苦于以下问题:Java CompletionStage.thenApply方法的具体用法?Java CompletionStage.thenApply怎么用?Java CompletionStage.thenApply使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.CompletionStage
的用法示例。
在下文中一共展示了CompletionStage.thenApply方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: index
import java.util.concurrent.CompletionStage; //导入方法依赖的package包/类
/**
* @return Service health details.
*/
public CompletionStage<Result> index() {
Status storageClientStatus = this.storageClient.ping();
CompletionStage<Status> keyValueStorageStatusResult = this.keyValueClient.pingAsync();
return keyValueStorageStatusResult
.thenApply(keyValueStatus -> ok(toJson(
new StatusApiModel(storageClientStatus, keyValueStatus))));
}
示例2: thenStage
import java.util.concurrent.CompletionStage; //导入方法依赖的package包/类
@Override
public <U> StagedFutureTimeout<U> thenStage(CompletionStage<U> stage) {
// async isn't necessary - it's just a conversion to optional
return new StagedFutureImpl<>(stage.thenApply(Optional::of), executor, tracing);
}
示例3: whenSucceeded
import java.util.concurrent.CompletionStage; //导入方法依赖的package包/类
/**
* Return a new CompletionStage that calls the given handler iff the given stage
* completes successfully 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>> whenSucceeded(CompletionStage<Optional<T>> stage, Function<T, Optional<U>> handler)
{
return stage.thenApply(optional -> optional.flatMap(handler));
}
示例4: whenAborted
import java.util.concurrent.CompletionStage; //导入方法依赖的package包/类
/**
* Return a new CompletionStage that calls the given handler iff the given stage
* completes successfully 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>> whenAborted(CompletionStage<Optional<T>> stage, Supplier<Optional<U>> handler)
{
return stage.thenApply(optional -> optional.isPresent() ? Optional.empty() : handler.get());
}