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(scala.concurrent.Future<A> future)
          Deprecated. Since 2.2. Use wrap(Future) instead.
 
Method Summary
static
<A> F.Promise<A>
delayed(F.Function0<A> function, long delay, java.util.concurrent.TimeUnit unit)
          Create a Promise which, after a delay, will be redeemed with the result of a given function.
static
<A> F.Promise<A>
delayed(F.Function0<A> function, long delay, java.util.concurrent.TimeUnit unit, scala.concurrent.ExecutionContext ec)
          Create a Promise which, after a delay, will be redeemed with the result of a given function.
<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.
<B> F.Promise<B>
flatMap(F.Function<A,F.Promise<B>> function, scala.concurrent.ExecutionContext ec)
          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()
          Deprecated. Since 2.2. Use get(long, TimeUnit) or get(long) instead.
 A get(long timeout)
          Awaits for the promise to get the result.
 A get(java.lang.Long timeout)
          Deprecated. Since 2.2. Use {get(long) instead.
 A get(long timeout, java.util.concurrent.TimeUnit unit)
          Awaits for the promise to get the result.
 A get(java.lang.Long timeout, java.util.concurrent.TimeUnit unit)
          Deprecated. Since 2.2. Use get(long, TimeUnit) instead.
 scala.concurrent.Future<A> getWrappedPromise()
          Deprecated. Since 2.2. Use wrapped() instead.
<B> F.Promise<B>
map(F.Function<A,B> function)
          Maps this promise to a promise of type B.
<B> F.Promise<B>
map(F.Function<A,B> function, scala.concurrent.ExecutionContext ec)
          Maps this promise to a promise of type B.
 void onFailure(F.Callback<java.lang.Throwable> action)
          Perform the given action callback if the promise encounters an exception.
 void onFailure(F.Callback<java.lang.Throwable> action, scala.concurrent.ExecutionContext ec)
          Perform the given action callback if the promise encounters an exception.
 void onRedeem(F.Callback<A> action)
          Perform the given action callback when the Promise is redeemed.
 void onRedeem(F.Callback<A> action, scala.concurrent.ExecutionContext ec)
          Perform the given action callback when the Promise is redeemed.
<B> F.Promise<F.Either<A,B>>
or(F.Promise<B> another)
          combines the current promise with another promise using `or`
static
<A> F.Promise<A>
promise(F.Function0<A> function)
          Create a Promise which will be redeemed with the result of a given function.
static
<A> F.Promise<A>
promise(F.Function0<A> function, scala.concurrent.ExecutionContext ec)
          Create a Promise which will be redeemed with the result of a given Function0.
static
<A> F.Promise<A>
pure(A a)
          Create a new pure promise, that is, a promise with a constant value from the start.
 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.
 F.Promise<A> recover(F.Function<java.lang.Throwable,A> function, scala.concurrent.ExecutionContext ec)
          Wraps this promise in a promise that will handle exceptions thrown by this Promise.
static
<A> F.Promise<java.util.List<A>>
sequence(scala.concurrent.ExecutionContext ec, F.Promise<? extends A>... promises)
          Combine the given promises into a single promise for the list of results.
static
<A> F.Promise<java.util.List<A>>
sequence(F.Promise<? extends A>... promises)
          Combine the given promises into a single promise for the list of results.
static
<A> F.Promise<java.util.List<A>>
sequence(java.lang.Iterable<F.Promise<? extends A>> promises)
          Combine the given promises into a single promise for the list of results.
static
<A> F.Promise<java.util.List<A>>
sequence(java.lang.Iterable<F.Promise<? extends A>> promises, scala.concurrent.ExecutionContext ec)
          Combine the given promises into a single promise for the list of results.
static
<A> F.Promise<A>
throwing(java.lang.Throwable throwable)
          Create a new promise throwing an exception.
static F.Promise<scala.Unit> timeout()
          Deprecated. Since 2.2. Use timeout(long) or timeout(long, TimeUnit) instead.
static
<A> F.Promise<A>
timeout(A message, long delay)
          Create a Promise that is redeemed after a timeout.
static
<A> F.Promise<A>
timeout(A message, java.lang.Long delay)
          Deprecated. Since 2.2. Use timeout(Object, long) instead.
static
<A> F.Promise<A>
timeout(A message, long delay, java.util.concurrent.TimeUnit unit)
          Create a Promise that is redeemed after a timeout.
static
<A> F.Promise<A>
timeout(A message, java.lang.Long delay, java.util.concurrent.TimeUnit unit)
          Deprecated. Since 2.2. Use timeout(Object, long, TimeUnit) instead.
static
<A> F.Promise<scala.Unit>
timeout(long delay)
          Create a Promise timer that throws a TimeoutException after a given timeout.
static
<A> F.Promise<scala.Unit>
timeout(long delay, java.util.concurrent.TimeUnit unit)
          Create a Promise timer that throws a TimeoutException after a given timeout.
static
<A> F.Promise<java.util.List<A>>
waitAll(F.Promise<? extends A>... promises)
          Deprecated. Since 2.1. Use #sequence(Promise...) instead.
static
<A> F.Promise<java.util.List<A>>
waitAll(java.lang.Iterable<F.Promise<? extends A>> promises)
          Deprecated. Since 2.1. Use sequence(Iterable) instead.
static
<A> F.Promise<A>
wrap(scala.concurrent.Future<A> future)
          Creates a Promise that wraps a Scala Future.
 scala.concurrent.Future<A> wrapped()
          Gets the Scala Future wrapped by this Promise.
<B> F.Promise<F.Tuple<A,B>>
zip(F.Promise<B> another)
          Zips the values of this promise with another, and creates a new promise holding the tuple of their results
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

F.Promise

@Deprecated
public F.Promise(scala.concurrent.Future<A> future)
Deprecated. Since 2.2. Use wrap(Future) instead.

Creates a Promise that wraps a Scala Future.

Parameters:
future - The Scala Future to wrap
Method Detail

wrap

public static <A> F.Promise<A> wrap(scala.concurrent.Future<A> future)
Creates a Promise that wraps a Scala Future.

Parameters:
future - The Scala Future to wrap

sequence

public static <A> F.Promise<java.util.List<A>> sequence(F.Promise<? extends A>... promises)
Combine the given promises into a single promise for the list of results. The sequencing operations are performed in the default ExecutionContext.

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

sequence

public static <A> F.Promise<java.util.List<A>> sequence(scala.concurrent.ExecutionContext ec,
                                                        F.Promise<? extends A>... promises)
Combine the given promises into a single promise for the list of results.

Parameters:
ec - Used to execute the sequencing operations.
promises - The promises to combine
Returns:
A single promise whose methods act on the list of redeemed promises

waitAll

@Deprecated
public static <A> F.Promise<java.util.List<A>> waitAll(F.Promise<? extends A>... promises)
Deprecated. Since 2.1. Use #sequence(Promise...) instead.

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

timeout

public static <A> F.Promise<A> timeout(A message,
                                       long delay,
                                       java.util.concurrent.TimeUnit unit)
Create a Promise that is redeemed after a timeout.

Parameters:
message - The message to use to redeem the Promise.
delay - The delay (expressed with the corresponding unit).
unit - The Unit.

timeout

@Deprecated
public static <A> F.Promise<A> timeout(A message,
                                                  java.lang.Long delay,
                                                  java.util.concurrent.TimeUnit unit)
Deprecated. Since 2.2. Use timeout(Object, long, TimeUnit) instead.

Create a Promise that is redeemed after a timeout.

Parameters:
message - The message to use to redeem the Promise.
delay - The delay (expressed with the corresponding unit).
unit - The Unit.

timeout

@Deprecated
public static F.Promise<scala.Unit> timeout()
                                     throws java.util.concurrent.TimeoutException
Deprecated. Since 2.2. Use timeout(long) or timeout(long, TimeUnit) instead.

Create a Promise timer that throws a TimeoutException after the default timeout duration expires. The returned Promise is usually combined with other Promises.

Returns:
a promise without a real value
Throws:
java.util.concurrent.TimeoutException

timeout

public static <A> F.Promise<A> timeout(A message,
                                       long delay)
Create a Promise that is redeemed after a timeout.

Parameters:
message - The message to use to redeem the Promise.
delay - The delay expressed in milliseconds.

timeout

@Deprecated
public static <A> F.Promise<A> timeout(A message,
                                                  java.lang.Long delay)
Deprecated. Since 2.2. Use timeout(Object, long) instead.

Create a Promise that is redeemed after a timeout.

Parameters:
message - The message to use to redeem the Promise.
delay - The delay expressed in milliseconds.

timeout

public static <A> F.Promise<scala.Unit> timeout(long delay)
Create a Promise timer that throws a TimeoutException after a given timeout. The returned Promise is usually combined with other Promises.

Parameters:
delay - The delay expressed in milliseconds.
Returns:
a promise without a real value

timeout

public static <A> F.Promise<scala.Unit> timeout(long delay,
                                                java.util.concurrent.TimeUnit unit)
Create a Promise timer that throws a TimeoutException after a given timeout. The returned Promise is usually combined with other Promises.

Parameters:
delay - The delay (expressed with the corresponding unit).
unit - The Unit.
Returns:
a promise without a real value

sequence

public static <A> F.Promise<java.util.List<A>> sequence(java.lang.Iterable<F.Promise<? extends A>> promises)
Combine the given promises into a single promise for the list of results. The sequencing operations are performed in the default ExecutionContext.

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

sequence

public static <A> F.Promise<java.util.List<A>> sequence(java.lang.Iterable<F.Promise<? extends A>> promises,
                                                        scala.concurrent.ExecutionContext ec)
Combine the given promises into a single promise for the list of results.

Parameters:
promises - The promises to combine
ec - Used to execute the sequencing operations.
Returns:
A single promise whose methods act on the list of redeemed promises

waitAll

@Deprecated
public static <A> F.Promise<java.util.List<A>> waitAll(java.lang.Iterable<F.Promise<? extends A>> promises)
Deprecated. Since 2.1. Use sequence(Iterable) instead.

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

pure

public static <A> F.Promise<A> pure(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

throwing

public static <A> F.Promise<A> throwing(java.lang.Throwable throwable)
Create a new promise throwing an exception.

Parameters:
throwable - Value to throw

promise

public static <A> F.Promise<A> promise(F.Function0<A> function)
Create a Promise which will be redeemed with the result of a given function. The Function0 will be run in the default ExecutionContext.

Parameters:
function - Used to fulfill the Promise.

promise

public static <A> F.Promise<A> promise(F.Function0<A> function,
                                       scala.concurrent.ExecutionContext ec)
Create a Promise which will be redeemed with the result of a given Function0.

Parameters:
function - Used to fulfill the Promise.
ec - The ExecutionContext to run the function in.

delayed

public static <A> F.Promise<A> delayed(F.Function0<A> function,
                                       long delay,
                                       java.util.concurrent.TimeUnit unit)
Create a Promise which, after a delay, will be redeemed with the result of a given function. The function will be called after the delay. The function will be run in the default ExecutionContext.

Parameters:
function - The function to call to fulfill the Promise.
delay - The time to wait.
unit - The units to use for the delay.

delayed

public static <A> F.Promise<A> delayed(F.Function0<A> function,
                                       long delay,
                                       java.util.concurrent.TimeUnit unit,
                                       scala.concurrent.ExecutionContext ec)
Create a Promise which, after a delay, will be redeemed with the result of a given function. The function will be called after the delay.

Parameters:
function - The function to call to fulfill the Promise.
delay - The time to wait.
unit - The units to use for the delay.
ec - The ExecutionContext to run the Function0 in.

get

@Deprecated
public A get()
Deprecated. Since 2.2. Use get(long, TimeUnit) or get(long) instead.

Awaits for the promise to get the result using a default timeout (currently 10000 milliseconds).
Throws a Throwable if the calculation providing the promise threw an exception

Returns:
The promised object

get

@Deprecated
public A get(java.lang.Long timeout,
                        java.util.concurrent.TimeUnit unit)
Deprecated. Since 2.2. Use get(long, TimeUnit) instead.

Awaits for the promise to get the result.
Throws a Throwable if the calculation providing the promise threw an exception

Parameters:
timeout - A user defined timeout
unit - timeout for timeout
Returns:
The promised result

get

public A get(long timeout,
             java.util.concurrent.TimeUnit unit)
Awaits for the promise to get the result. Throws a Throwable if the calculation providing the promise threw an exception

Parameters:
timeout - A user defined timeout
unit - timeout for timeout
Returns:
The promised result

get

@Deprecated
public A get(java.lang.Long timeout)
Deprecated. Since 2.2. Use {get(long) instead.

Awaits for the promise to get the result.
Throws a Throwable if the calculation providing the promise threw an exception

Parameters:
timeout - A user defined timeout in milliseconds
Returns:
The promised result

get

public A get(long timeout)
Awaits for the promise to get the result.

Parameters:
timeout - A user defined timeout in milliseconds
Returns:
The promised result

or

public <B> F.Promise<F.Either<A,B>> or(F.Promise<B> another)
combines the current promise with another promise using `or`

Parameters:
another -

onRedeem

public void onRedeem(F.Callback<A> action)
Perform the given action callback when the Promise is redeemed. The callback will be run in the default execution context.

Parameters:
action - The action to perform.

onRedeem

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

Parameters:
action - The action to perform.
ec - The ExecutionContext to execute the action in.

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. The function will be run in the default execution context.

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

map

public <B> F.Promise<B> map(F.Function<A,B> function,
                            scala.concurrent.ExecutionContext ec)
Maps this promise to a promise of type B. The function function is applied as soon as the promise is redeemed.

Parameters:
function - The function to map A to B.
ec - The ExecutionContext to execute the function in.
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. The function will be run in the default execution context.

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.

recover

public F.Promise<A> recover(F.Function<java.lang.Throwable,A> function,
                            scala.concurrent.ExecutionContext ec)
Wraps this promise in a promise that will handle exceptions thrown by this Promise.

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.
ec - The ExecutionContext to execute the function in.
Returns:
A wrapped promise that will only throw an exception if the supplied function throws an exception.

onFailure

public void onFailure(F.Callback<java.lang.Throwable> action)
Perform the given action callback if the promise encounters an exception. This action will be run in the default exceution context.

Parameters:
action - The action to perform.

onFailure

public void onFailure(F.Callback<java.lang.Throwable> action,
                      scala.concurrent.ExecutionContext ec)
Perform the given action callback if the promise encounters an exception.

Parameters:
action - The action to perform.
ec - The ExecutionContext to execute the callback in.

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. The function will be run in the default execution context.

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

flatMap

public <B> F.Promise<B> flatMap(F.Function<A,F.Promise<B>> function,
                                scala.concurrent.ExecutionContext ec)
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.

Parameters:
function - The function to map A to a promise for B.
ec - The ExecutionContext to execute the function in.
Returns:
A wrapped promise for a result of type B

zip

public <B> F.Promise<F.Tuple<A,B>> zip(F.Promise<B> another)
Zips the values of this promise with another, and creates a new promise holding the tuple of their results

Parameters:
another -

wrapped

public scala.concurrent.Future<A> wrapped()
Gets the Scala Future wrapped by this Promise.

Returns:
The Scala Future

getWrappedPromise

@Deprecated
public scala.concurrent.Future<A> getWrappedPromise()
Deprecated. Since 2.2. Use wrapped() instead.

Gets the Scala Future wrapped by this Promise.

Returns:
The Scala Future