Package org.apache.pekko.dispatch
Class CompletionStages$
java.lang.Object
org.apache.pekko.dispatch.CompletionStages$
CompletionStages provides utilities for working with
CompletionStages.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CompletionStages$Static reference to the singleton instance of this Scala object. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> scala.concurrent.Future<T>asScala(CompletionStage<T> stage) Convert aCompletionStageto a ScalaFuture.<T> CompletionStage<Optional<T>>find(Iterable<? extends CompletionStage<? extends T>> stages, Function<T, Boolean> predicate) Return the firstCompletionStagein the givenIterablethat matches the given predicate.<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.<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.<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.<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.<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.
-
Field Details
-
MODULE$
Static reference to the singleton instance of this Scala object.
-
-
Constructor Details
-
CompletionStages$
public CompletionStages$()
-
-
Method Details
-
asScala
Convert aCompletionStageto a ScalaFuture. -
find
public <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 <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 <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 <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 <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 <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
-