Package org.apache.pekko.dispatch
Class CompletionStages
java.lang.Object
org.apache.pekko.dispatch.CompletionStages
CompletionStages provides utilities for working with
CompletionStages.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> scala.concurrent.Future<T>asScala(CompletionStage<T> stage) Convert aCompletionStageto a ScalaFuture.static <T> CompletionStage<Optional<T>>find(Iterable<? extends CompletionStage<? extends T>> stages, Function<T, Boolean> predicate) Return the firstCompletionStagein the givenIterablethat matches the given predicate.static <T> CompletionStage<T>firstCompletedOf(Iterable<? extends CompletionStage<? extends T>> stages) Returns a newCompletionStagethat, when completed, will contain the result of the first of the given stages to complete, with the same value or exception.static <T,R> CompletionStage<R> fold(R zero, Iterable<? extends CompletionStage<? extends T>> stages, Function2<R, T, R> function) Aggregate the results of the given stages using the given associative function and a zero value.static <T,R> CompletionStage<R> reduce(Iterable<? extends CompletionStage<? extends T>> stages, Function2<R, T, R> function) Reduce the results of the given stages using the given associative function.static <T> CompletionStage<List<T>>sequence(Iterable<? extends CompletionStage<? extends T>> stages, Executor executor) Transform ajava.lang.IterableofCompletionStages into a singleCompletionStagewith ajava.util.Listof all the results.static <T,R> CompletionStage<List<R>> traverse(Iterable<T> input, Function<T, CompletionStage<R>> function, Executor executor) Transform ajava.lang.IterableofCompletionStages into a singleCompletionStagewith ajava.util.Listof all the results.
-
Constructor Details
-
CompletionStages
public CompletionStages()
-
-
Method Details
-
asScala
Convert aCompletionStageto a ScalaFuture. -
find
public static <T> CompletionStage<Optional<T>> find(Iterable<? extends CompletionStage<? extends T>> stages, Function<T, Boolean> predicate) Return the firstCompletionStagein the givenIterablethat matches the given predicate. If no stage matches the predicate, an emptyOptionalis returned.- Parameters:
stages- the stages to search throughpredicate- the predicate to apply to each completed stage- Returns:
- a
CompletionStagethat, when completed, will contain anOptionalwith the first matching element, or an emptyOptionalif none matched - Since:
- 1.2.0
-
firstCompletedOf
public static <T> CompletionStage<T> firstCompletedOf(Iterable<? extends CompletionStage<? extends T>> stages) Returns a newCompletionStagethat, when completed, will contain the result of the first of the given stages to complete, with the same value or exception.If the given iterable is empty, the returned stage never completes.
- Parameters:
stages- the stages- Returns:
- a
CompletionStagethat, when completed, will contain the result of the first stage to complete with the same value or exception. - Since:
- 1.2.0
-
fold
public static <T,R> CompletionStage<R> fold(R zero, Iterable<? extends CompletionStage<? extends T>> stages, Function2<R, T, R> function) Aggregate the results of the given stages using the given associative function and a zero value. The stages are processed in the order they are given.- Parameters:
zero- the zero valuestages- the stages to aggregatefunction- the associative function to use for aggregation- Returns:
- a
CompletionStagethat, when completed, will contain the aggregated result - Since:
- 1.2.0
-
reduce
public static <T,R> CompletionStage<R> reduce(Iterable<? extends CompletionStage<? extends T>> stages, Function2<R, T, R> function) Reduce the results of the given stages using the given associative function. The stages are processed in the order they are given. If the given iterable is empty, the returned stage is completed with aNoSuchElementException.- Parameters:
stages- the stages to reducefunction- the associative function to use for reduction- Returns:
- a
CompletionStagethat, when completed, will contain the reduced result of the stages or aNoSuchElementExceptionif the given iterable is empty - Since:
- 1.2.0
-
sequence
public static <T> CompletionStage<List<T>> sequence(Iterable<? extends CompletionStage<? extends T>> stages, Executor executor) Transform ajava.lang.IterableofCompletionStages into a singleCompletionStagewith ajava.util.Listof all the results. The stages are processed in the order they are given.- Parameters:
stages- the stages to sequenceexecutor- the executor to use for asynchronous execution, ornullto use synchronous execution- Returns:
- a
CompletionStagethat, when completed, will contain ajava.util.Listwith all the results - Since:
- 1.2.0
-
traverse
public static <T,R> CompletionStage<List<R>> traverse(Iterable<T> input, Function<T, CompletionStage<R>> function, Executor executor) Transform ajava.lang.IterableofCompletionStages into a singleCompletionStagewith ajava.util.Listof all the results. The stages are processed in the order they are given.- Parameters:
input- the input iterablefunction- the function to apply to each elementexecutor- the executor to use for asynchronous execution, ornullto use synchronous execution- Returns:
- a
CompletionStagethat, when completed, will contain ajava.util.Listwith all the results - Since:
- 1.2.0
-