T - The value type associated with this Promise.@ProviderType
public interface Promise<T>
final PromiseExample chaining usage;foo= foo(); foo.onResolve(new Runnable() { public void run() { System.out.println(foo.getValue()); } });
Successdoubler = new Success () { public Promise call(Promise p) throws Exception { return Promises.resolved(p.getValue()+p.getValue()); } }; final Promise foo = foo().then(doubler).then(doubler); foo.onResolve(new Runnable() { public void run() { System.out.println(foo.getValue()); } });
| Modifier and Type | Method and Description |
|---|---|
Promise<T> |
fallbackTo(Promise<? extends T> fallback)
Fall back to the value of the specified Promise if this Promise fails.
|
Promise<T> |
filter(Predicate<? super T> predicate)
Filter the value of this Promise.
|
<R> Promise<R> |
flatMap(Function<? super T,Promise<? extends R>> mapper)
FlatMap the value of this Promise.
|
Throwable |
getFailure()
Returns the failure of this Promise.
|
T |
getValue()
Returns the value of this Promise.
|
boolean |
isDone()
Returns whether this Promise has been resolved.
|
<R> Promise<R> |
map(Function<? super T,? extends R> mapper)
Map the value of this Promise.
|
Promise<T> |
onResolve(Runnable callback)
Register a callback to be called when this Promise is resolved.
|
Promise<T> |
recover(Function<Promise<?>,? extends T> recovery)
Recover from a failure of this Promise with a recovery value.
|
Promise<T> |
recoverWith(Function<Promise<?>,Promise<? extends T>> recovery)
Recover from a failure of this Promise with a recovery Promise.
|
<R> Promise<R> |
then(Success<? super T,? extends R> success)
Chain a new Promise to this Promise with a Success callback.
|
<R> Promise<R> |
then(Success<? super T,? extends R> success,
Failure failure)
Chain a new Promise to this Promise with Success and Failure callbacks.
|
boolean isDone()
T getValue() throws InvocationTargetException, InterruptedException
InvocationTargetException - If this Promise was resolved with a failure. The cause of the
InvocationTargetException is the failure exception.InterruptedException - If the current thread was interrupted while waiting.Throwable getFailure() throws InterruptedException
InterruptedException - If the current thread was interrupted while waiting.Promise<T> onResolve(Runnable callback)
callback - A callback to be called when this Promise is resolved. Must not be null.<R> Promise<R> then(Success<? super T,? extends R> success, Failure failure)
R - The value type associated with the returned Promise.success - A Success callback to be called when this Promise is successfully resolved. May be null if no
Success callback is required. In thifailure - A Failure callback to be called when this Promise is resolved with a failure. May be null if no
Failure callback is required.<R> Promise<R> then(Success<? super T,? extends R> success)
R - The value type associated with the returned Promise.success - A Success callback to be called when this Promise is successfully resolved. May be null if no
Success callback is required. In this case, the returned Promise must be resolved with the value
null when this Promise is successfully resolved.then(Success, Failure)Promise<T> filter(Predicate<? super T> predicate)
predicate - The Predicate to evaluate the value of this Promise. Must not be null.<R> Promise<R> map(Function<? super T,? extends R> mapper)
R - The value type associated with the returned Promise.mapper - The Function that will map the value of this Promise to the value that will be used to resolve the
returned Promise. Must not be null.<R> Promise<R> flatMap(Function<? super T,Promise<? extends R>> mapper)
R - The value type associated with the returned Promise.mapper - The Function that will flatMap the value of this Promise to a Promise that will be used to resolve
the returned Promise. Must not be null.Promise<T> recover(Function<Promise<?>,? extends T> recovery)
recovery - If this Promise resolves with a failure, the specified Function is called to produce a recovery
value to be used to resolve the returned Promise. Must not be null.Promise<T> recoverWith(Function<Promise<?>,Promise<? extends T>> recovery)
recovery - If this Promise resolves with a failure, the specified Function is called to produce a recovery
Promise to be used to resolve the returned Promise. Must not be null.Promise<T> fallbackTo(Promise<? extends T> fallback)
fallback - The Promise whose value will be used to resolve the returned Promise if this Promise resolves
with a failure. Must not be null.Copyright © 2009-2015 The Apache Software Foundation. All Rights Reserved.