Package akka.dispatch

Class Futures


  • public class Futures
    extends java.lang.Object
    Futures is the Java API for Futures and Promises
    • Constructor Summary

      Constructors 
      Constructor Description
      Futures()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> scala.concurrent.Future<T> failed​(java.lang.Throwable exception)
      creates an already completed Promise with the specified exception
      static <T> java.util.concurrent.CompletionStage<T> failedCompletionStage​(java.lang.Throwable ex)
      Creates an already completed CompletionStage with the specified exception
      static <T> scala.concurrent.Future<Option<T>> find​(java.lang.Iterable<scala.concurrent.Future<T>> futures, Function<T,​java.lang.Boolean> predicate, scala.concurrent.ExecutionContext executor)
      Returns a Future that will hold the optional result of the first Future with a result that matches the predicate
      static <T> scala.concurrent.Future<T> firstCompletedOf​(java.lang.Iterable<scala.concurrent.Future<T>> futures, scala.concurrent.ExecutionContext executor)
      Returns a Future to the result of the first future in the list that is completed
      static <T,​R>
      scala.concurrent.Future<R>
      fold​(R zero, java.lang.Iterable<scala.concurrent.Future<T>> futures, Function2<R,​T,​R> fun, scala.concurrent.ExecutionContext executor)
      A non-blocking fold over the specified futures, with the start value of the given zero.
      static <T> scala.concurrent.Future<T> future​(java.util.concurrent.Callable<T> body, scala.concurrent.ExecutionContext executor)
      Starts an asynchronous computation and returns a Future object with the result of that computation.
      static <T> scala.concurrent.Promise<T> promise()
      Creates a promise object which can be completed with a value.
      static <T,​R>
      scala.concurrent.Future<R>
      reduce​(java.lang.Iterable<scala.concurrent.Future<T>> futures, Function2<R,​T,​R> fun, scala.concurrent.ExecutionContext executor)
      Reduces the results of the supplied futures and binary function.
      static <A> scala.concurrent.Future<java.lang.Iterable<A>> sequence​(java.lang.Iterable<scala.concurrent.Future<A>> in, scala.concurrent.ExecutionContext executor)
      static <T> scala.concurrent.Future<T> successful​(T result)
      Creates an already completed Promise with the specified result
      static <A,​B>
      scala.concurrent.Future<java.lang.Iterable<B>>
      traverse​(java.lang.Iterable<A> in, Function<A,​scala.concurrent.Future<B>> fn, scala.concurrent.ExecutionContext executor)
      Transforms a JIterable[A] into a Future[JIterable[B} using the provided Function A ⇒ Future[B].
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Futures

        public Futures()
    • Method Detail

      • future

        public static <T> scala.concurrent.Future<T> future​(java.util.concurrent.Callable<T> body,
                                                            scala.concurrent.ExecutionContext executor)
        Starts an asynchronous computation and returns a Future object with the result of that computation.

        The result becomes available once the asynchronous computation is completed.

        Parameters:
        body - the asynchronous computation
        executor - the execution context on which the future is run
        Returns:
        the Future holding the result of the computation
      • promise

        public static <T> scala.concurrent.Promise<T> promise()
        Creates a promise object which can be completed with a value.

        Returns:
        the newly created Promise object
      • failed

        public static <T> scala.concurrent.Future<T> failed​(java.lang.Throwable exception)
        creates an already completed Promise with the specified exception
        Parameters:
        exception - (undocumented)
        Returns:
        (undocumented)
      • successful

        public static <T> scala.concurrent.Future<T> successful​(T result)
        Creates an already completed Promise with the specified result
        Parameters:
        result - (undocumented)
        Returns:
        (undocumented)
      • failedCompletionStage

        public static <T> java.util.concurrent.CompletionStage<T> failedCompletionStage​(java.lang.Throwable ex)
        Creates an already completed CompletionStage with the specified exception
        Parameters:
        ex - (undocumented)
        Returns:
        (undocumented)
      • find

        public static <T> scala.concurrent.Future<Option<T>> find​(java.lang.Iterable<scala.concurrent.Future<T>> futures,
                                                                  Function<T,​java.lang.Boolean> predicate,
                                                                  scala.concurrent.ExecutionContext executor)
        Returns a Future that will hold the optional result of the first Future with a result that matches the predicate
        Parameters:
        futures - (undocumented)
        predicate - (undocumented)
        executor - (undocumented)
        Returns:
        (undocumented)
      • firstCompletedOf

        public static <T> scala.concurrent.Future<T> firstCompletedOf​(java.lang.Iterable<scala.concurrent.Future<T>> futures,
                                                                      scala.concurrent.ExecutionContext executor)
        Returns a Future to the result of the first future in the list that is completed
        Parameters:
        futures - (undocumented)
        executor - (undocumented)
        Returns:
        (undocumented)
      • fold

        public static <T,​R> scala.concurrent.Future<R> fold​(R zero,
                                                                  java.lang.Iterable<scala.concurrent.Future<T>> futures,
                                                                  Function2<R,​T,​R> fun,
                                                                  scala.concurrent.ExecutionContext executor)
        A non-blocking fold over the specified futures, with the start value of the given zero. The fold is performed on the thread where the last future is completed, the result will be the first failure of any of the futures, or any failure in the actual fold, or the result of the fold.
        Parameters:
        zero - (undocumented)
        futures - (undocumented)
        fun - (undocumented)
        executor - (undocumented)
        Returns:
        (undocumented)
      • reduce

        public static <T,​R> scala.concurrent.Future<R> reduce​(java.lang.Iterable<scala.concurrent.Future<T>> futures,
                                                                    Function2<R,​T,​R> fun,
                                                                    scala.concurrent.ExecutionContext executor)
        Reduces the results of the supplied futures and binary function.
        Parameters:
        futures - (undocumented)
        fun - (undocumented)
        executor - (undocumented)
        Returns:
        (undocumented)
      • traverse

        public static <A,​B> scala.concurrent.Future<java.lang.Iterable<B>> traverse​(java.lang.Iterable<A> in,
                                                                                          Function<A,​scala.concurrent.Future<B>> fn,
                                                                                          scala.concurrent.ExecutionContext executor)
        Transforms a JIterable[A] into a Future[JIterable[B} using the provided Function A ⇒ Future[B]. This is useful for performing a parallel map. For example, to apply a function to all items of a list in parallel.
        Parameters:
        in - (undocumented)
        fn - (undocumented)
        executor - (undocumented)
        Returns:
        (undocumented)