akka.dispatch
Class Futures$

java.lang.Object
  extended by akka.dispatch.Futures$

public class Futures$
extends java.lang.Object

Futures is the Java API for Futures and Promises


Field Summary
static Futures$ MODULE$
          Static reference to the singleton instance of this Scala object.
 
Constructor Summary
Futures$()
           
 
Method Summary
<T> scala.concurrent.Future<T>
failed(java.lang.Throwable exception)
          Creates an already completed Promise with the specified exception
<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
<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
<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.
<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.
<T> scala.concurrent.Promise<T>
promise()
          Creates a promise object which can be completed with a value.
<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.
<A> scala.concurrent.Future<java.lang.Iterable<A>>
sequence(java.lang.Iterable<scala.concurrent.Future<A>> in, scala.concurrent.ExecutionContext executor)
          Simple version of traverse(java.lang.Iterable, akka.japi.Function>, scala.concurrent.ExecutionContext).
<T> scala.concurrent.Future<T>
successful(T result)
          Creates an already completed Promise with the specified result
<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
 

Field Detail

MODULE$

public static final Futures$ MODULE$
Static reference to the singleton instance of this Scala object.

Constructor Detail

Futures$

public Futures$()
Method Detail

future

public <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 asychronous computation
executor - the execution context on which the future is run
Returns:
the Future holding the result of the computation

promise

public <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 <T> scala.concurrent.Future<T> failed(java.lang.Throwable exception)
Creates an already completed Promise with the specified exception


successful

public <T> scala.concurrent.Future<T> successful(T result)
Creates an already completed Promise with the specified result


find

public <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


firstCompletedOf

public <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


fold

public <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.


reduce

public <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.


sequence

public <A> scala.concurrent.Future<java.lang.Iterable<A>> sequence(java.lang.Iterable<scala.concurrent.Future<A>> in,
                                                                   scala.concurrent.ExecutionContext executor)
Simple version of traverse(java.lang.Iterable, akka.japi.Function>, scala.concurrent.ExecutionContext). Transforms a JIterable[Future[A} into a Future[JIterable[A}. Useful for reducing many Futures into a single Future.


traverse

public <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.