Class CompletionStages$

java.lang.Object
org.apache.pekko.dispatch.CompletionStages$

public class CompletionStages$ extends Object
CompletionStages provides utilities for working with CompletionStages.
  • Field Details

    • MODULE$

      public static final CompletionStages$ MODULE$
      Static reference to the singleton instance of this Scala object.
  • Constructor Details

    • CompletionStages$

      public CompletionStages$()
  • Method Details

    • asScala

      public <T> scala.concurrent.Future<T> asScala(CompletionStage<T> stage)
      Convert a CompletionStage to a Scala Future.
    • find

      public <T> CompletionStage<Optional<T>> find(Iterable<? extends CompletionStage<? extends T>> stages, Function<T,Boolean> predicate)
      Return the first CompletionStage in the given Iterable that matches the given predicate. If no stage matches the predicate, an empty Optional is returned.

      Parameters:
      stages - the stages to search through
      predicate - the predicate to apply to each completed stage
      Returns:
      a CompletionStage that, when completed, will contain an Optional with the first matching element, or an empty Optional if none matched
      Since:
      1.2.0
    • firstCompletedOf

      public <T> CompletionStage<T> firstCompletedOf(Iterable<? extends CompletionStage<? extends T>> stages)
      Returns a new CompletionStage that, 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 CompletionStage that, 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 value
      stages - the stages to aggregate
      function - the associative function to use for aggregation
      Returns:
      a CompletionStage that, 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 a NoSuchElementException.

      Parameters:
      stages - the stages to reduce
      function - the associative function to use for reduction
      Returns:
      a CompletionStage that, when completed, will contain the reduced result of the stages or a NoSuchElementException if 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 a java.lang.Iterable of CompletionStages into a single CompletionStage with a java.util.List of all the results. The stages are processed in the order they are given.

      Parameters:
      stages - the stages to sequence
      executor - the executor to use for asynchronous execution, or null to use synchronous execution
      Returns:
      a CompletionStage that, when completed, will contain a java.util.List with 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 a java.lang.Iterable of CompletionStages into a single CompletionStage with a java.util.List of all the results. The stages are processed in the order they are given.

      Parameters:
      input - the input iterable
      function - the function to apply to each element
      executor - the executor to use for asynchronous execution, or null to use synchronous execution
      Returns:
      a CompletionStage that, when completed, will contain a java.util.List with all the results
      Since:
      1.2.0