本文整理汇总了Java中java.util.concurrent.CompletionStage.thenCompose方法的典型用法代码示例。如果您正苦于以下问题:Java CompletionStage.thenCompose方法的具体用法?Java CompletionStage.thenCompose怎么用?Java CompletionStage.thenCompose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.CompletionStage
的用法示例。
在下文中一共展示了CompletionStage.thenCompose方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: displayExceptionPane
import java.util.concurrent.CompletionStage; //导入方法依赖的package包/类
public static CompletionStage<Stage> displayExceptionPane(
final String title,
final String readable,
final Throwable exception
) {
final Pane exceptionPane = new ExceptionHandler(exception).asPane(readable);
final CompletionStage<Stage> exceptionStage = Stages.stageOf(title, exceptionPane);
return exceptionStage.thenCompose(Stages::scheduleDisplaying);
}
示例2: updateBatches
import java.util.concurrent.CompletionStage; //导入方法依赖的package包/类
/**
* Given a list of update actions batches represented by a {@link List}<{@link List}> of {@link UpdateAction},
* this method executes the update command, computed by {@code updateCommandFunction}, on each batch.
*
* @param result in the first call of this method, this result is normally a completed
* future containing the resource to update, it is then used within each iteration of
* batch execution to have the latest resource (with version) once the previous batch
* has finished execution.
* @param updateCommandFunction a {@link BiFunction} used to compute the update command required to update the
* resource.
* @param batches the batches of update actions to execute.
* @return an instance of {@link CompletionStage}<{@code U}> which contains as a result an instance of
* the resource {@link U} after all the update actions in all batches have been executed.
*/
@Nonnull
private CompletionStage<U> updateBatches(
@Nonnull final CompletionStage<U> result,
@Nonnull final BiFunction<U, List<? extends UpdateAction<U>>, UpdateCommand<U>> updateCommandFunction,
@Nonnull final List<List<UpdateAction<U>>> batches) {
CompletionStage<U> resultStage = result;
for (final List<UpdateAction<U>> batch : batches) {
resultStage = resultStage.thenCompose(updatedProduct ->
syncOptions.getCtpClient().execute(updateCommandFunction.apply(updatedProduct, batch)));
}
return resultStage;
}
示例3: queryNextPages
import java.util.concurrent.CompletionStage; //导入方法依赖的package包/类
/**
* Given a completion stage {@code currentPageStage} containing a current page result {@link PagedQueryResult}, this
* method composes the completion stage by first checking if the result is null or not. If it is not, then it
* recursivley (by calling itself with the next page's completion stage result) composes to the supplied stage,
* stages of the all next pages' processing. If there is no next page, then the result of the
* {@code currentPageStage} would be null and this method would just return a completed future containing
* containing null result, which in turn signals the last page of processing.
*
* @param currentPageStage a future containing a result {@link PagedQueryResult}.
*/
@Nonnull
private CompletionStage<Void> queryNextPages(@Nonnull final CompletionStage<PagedQueryResult<T>> currentPageStage) {
return currentPageStage.thenCompose(currentPage ->
currentPage != null ? queryNextPages(processPageAndGetNext(currentPage)) : completedFuture(null));
}