play.libs
Class F.Promise<A>

java.lang.Object
  extended by play.libs.F.Promise<A>
Enclosing class:
F

public static class F.Promise<A>
extends java.lang.Object

A promise to produce a result of type A.


Constructor Summary
F.Promise(A a)
          Create a new pure promise, that is, a promise with a constant value from the start.
F.Promise(play.api.libs.concurrent.Promise<A> promise)
          Create a new promise wrapping the given Scala promise
 
Method Summary
<B> F.Promise<B>
flatMap(F.Function<A,F.Promise<B>> function)
          Maps the result of this promise to a promise for a result of type B, and flattens that to be a single promise for B.
 A get()
          Awaits for the promise to get the result using the default timeout (5000 milliseconds).
 A get(java.lang.Long timeout)
          Awaits for the promise to get the result.
 A get(java.lang.Long timeout, java.util.concurrent.TimeUnit unit)
          Awaits for the promise to get the result.
 play.api.libs.concurrent.Promise<A> getWrappedPromise()
          Get the underlying Scala promise
<B> F.Promise<B>
map(F.Function<A,B> function)
          Maps this promise to a promise of type B.
 void onRedeem(F.Callback<A> action)
          Perform the given action callback when the Promise is redeemed.
 F.Promise<A> recover(F.Function<java.lang.Throwable,A> function)
          Wraps this promise in a promise that will handle exceptions thrown by this Promise.
static
<A> F.Promise<java.util.List<A>>
waitAll(F.Promise<A>... promises)
          Combine the given promises into a single promise for the list of results.
static
<A> F.Promise<java.util.List<A>>
waitAll(java.lang.Iterable<F.Promise<A>> promises)
          Combine the given promises into a single promise for the list of results.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

F.Promise

public F.Promise(play.api.libs.concurrent.Promise<A> promise)
Create a new promise wrapping the given Scala promise

Parameters:
promise - The scala promise to wrap

F.Promise

public F.Promise(A a)
Create a new pure promise, that is, a promise with a constant value from the start.

Parameters:
a - the value for the promise
Method Detail

waitAll

public static <A> F.Promise<java.util.List<A>> waitAll(F.Promise<A>... promises)
Combine the given promises into a single promise for the list of results.

Parameters:
promises - The promises to combine
Returns:
A single promise whose methods act on the list of redeemed promises

waitAll

public static <A> F.Promise<java.util.List<A>> waitAll(java.lang.Iterable<F.Promise<A>> promises)
Combine the given promises into a single promise for the list of results.

Parameters:
promises - The promises to combine
Returns:
A single promise whose methods act on the list of redeemed promises

get

public A get()
Awaits for the promise to get the result using the default timeout (5000 milliseconds).

Returns:
The promised object
Throws:
java.lang.RuntimeException - if the calculation providing the promise threw an exception

get

public A get(java.lang.Long timeout,
             java.util.concurrent.TimeUnit unit)
Awaits for the promise to get the result.

Parameters:
timeout - A user defined timeout
unit - timeout for timeout
Returns:
The promised result
Throws:
java.lang.RuntimeException - if the calculation providing the promise threw an exception

get

public A get(java.lang.Long timeout)
Awaits for the promise to get the result.

Parameters:
timeout - A user defined timeout in milliseconds
Returns:
The promised result
Throws:
java.lang.RuntimeException - if the calculation providing the promise threw an exception

onRedeem

public void onRedeem(F.Callback<A> action)
Perform the given action callback when the Promise is redeemed.

Parameters:
action - The action to perform.

map

public <B> F.Promise<B> map(F.Function<A,B> function)
Maps this promise to a promise of type B. The function function is applied as soon as the promise is redeemed. Exceptions thrown by function will be wrapped in RuntimeException, unless they are RuntimeException's themselves.

Parameters:
function - The function to map A to B.
Returns:
A wrapped promise that maps the type from A to B.

recover

public F.Promise<A> recover(F.Function<java.lang.Throwable,A> function)
Wraps this promise in a promise that will handle exceptions thrown by this Promise. Exceptions thrown by function will be wrapped in RuntimeException, unless they are RuntimeException's themselves.

Parameters:
function - The function to handle the exception. This may, for example, convert the exception into something of type T, or it may throw another exception, or it may do some other handling.
Returns:
A wrapped promise that will only throw an exception if the supplied function throws an exception.

flatMap

public <B> F.Promise<B> flatMap(F.Function<A,F.Promise<B>> function)
Maps the result of this promise to a promise for a result of type B, and flattens that to be a single promise for B. Exceptions thrown by function will be wrapped in RuntimeException, unless they are RuntimeException's themselves.

Parameters:
function - The function to map A to a promise for B.
Returns:
A wrapped promise for a result of type B

getWrappedPromise

public play.api.libs.concurrent.Promise<A> getWrappedPromise()
Get the underlying Scala promise

Returns:
The scala promise