public final class PromiseImpl<T> extends Object implements PromiseInternal<T>, Listener<T>
| Modifier and Type | Field and Description |
|---|---|
protected ContextInternal |
context |
| Constructor and Description |
|---|
PromiseImpl()
Create a promise that hasn't completed yet
|
PromiseImpl(ContextInternal context)
Create a promise that hasn't completed yet
|
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(Listener<T> listener)
Add a listener to the future result.
|
Throwable |
cause()
An exception describing failure.
|
<U> Future<U> |
compose(Function<T,Future<U>> successMapper,
Function<Throwable,Future<U>> failureMapper)
Compose this future with a
successMapper and failureMapper functions. |
ContextInternal |
context() |
protected <U> void |
emit(U value,
Handler<U> handler) |
protected void |
emitFailure(Throwable cause,
Listener<T> listener) |
protected void |
emitSuccess(T value,
Listener<T> listener) |
<U> Future<T> |
eventually(Function<Void,Future<U>> mapper)
Compose this future with a
mapper that will be always be called. |
boolean |
failed()
Did it fail?
|
protected void |
formatValue(Object value,
StringBuilder sb) |
Future<T> |
future() |
void |
handle(AsyncResult<T> ar)
Succeed or fail this promise with the
AsyncResult event. |
boolean |
isComplete()
Has it completed?
|
<U> Future<U> |
map(Function<T,U> mapper)
Apply a
mapper function on this future. |
<V> Future<V> |
map(V value)
Map the result of a future to a specific
value. |
Future<T> |
onComplete(Handler<AsyncResult<T>> handler)
Add a handler to be notified of the result.
|
Future<T> |
onFailure(Handler<Throwable> handler)
Add a handler to be notified of the failed result.
|
void |
onFailure(Throwable failure)
Signal the failure
|
Future<T> |
onSuccess(Handler<T> handler)
Add a handler to be notified of the succeeded result.
|
void |
onSuccess(T value)
Signal the success.
|
void |
operationComplete(io.netty.util.concurrent.Future<T> future) |
Future<T> |
otherwise(Function<Throwable,T> mapper)
Apply a
mapper function on this future. |
Future<T> |
otherwise(T value)
Map the failure of a future to a specific
value. |
T |
result()
The result of the operation.
|
boolean |
succeeded()
Did it succeed?
|
String |
toString() |
<U> Future<U> |
transform(Function<AsyncResult<T>,Future<U>> mapper)
Transform this future with a
mapper functions. |
boolean |
tryComplete(T result) |
boolean |
tryFail(Throwable cause) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitcontextcomplete, complete, fail, fail, promise, tryComplete, tryComplete, tryFail, tryFailaddListenercause, compose, compose, eventually, failed, failedFuture, failedFuture, flatMap, fromCompletionStage, fromCompletionStage, future, isComplete, map, map, mapEmpty, onComplete, onFailure, onSuccess, otherwise, otherwise, otherwiseEmpty, recover, result, succeeded, succeededFuture, succeededFuture, toCompletionStage, transformprotected final ContextInternal context
public PromiseImpl()
public PromiseImpl(ContextInternal context)
public void handle(AsyncResult<T> ar)
PromiseAsyncResult event.public void onSuccess(T value)
Listenerpublic void onFailure(Throwable failure)
Listenerpublic void operationComplete(io.netty.util.concurrent.Future<T> future)
operationComplete in interface io.netty.util.concurrent.GenericFutureListener<io.netty.util.concurrent.Future<T>>public T result()
public Throwable cause()
public boolean succeeded()
public boolean failed()
public boolean isComplete()
public Future<T> onSuccess(Handler<T> handler)
Futurehandler - the handler that will be called with the succeeded resultpublic Future<T> onFailure(Handler<Throwable> handler)
Futurehandler - the handler that will be called with the failed resultpublic Future<T> onComplete(Handler<AsyncResult<T>> handler)
Futurehandler - the handler that will be called with the resultpublic void addListener(Listener<T> listener)
FutureInternallistener - the listenerpublic boolean tryComplete(T result)
public boolean tryFail(Throwable cause)
protected void formatValue(Object value, StringBuilder sb)
public final ContextInternal context()
context in interface FutureInternal<T>null when there is noneprotected final void emitSuccess(T value,
Listener<T> listener)
protected final <U> void emit(U value,
Handler<U> handler)
public <U> Future<U> compose(Function<T,Future<U>> successMapper, Function<Throwable,Future<U>> failureMapper)
FuturesuccessMapper and failureMapper functions.
When this future (the one on which compose is called) succeeds, the successMapper will be called with
the completed value and this mapper returns another future object. This returned future completion will complete
the future returned by this method call.
When this future (the one on which compose is called) fails, the failureMapper will be called with
the failure and this mapper returns another future object. This returned future completion will complete
the future returned by this method call.
If any mapper function throws an exception, the returned future will be failed with this exception.
public <U> Future<U> transform(Function<AsyncResult<T>,Future<U>> mapper)
Futuremapper functions.
When this future (the one on which transform is called) completes, the mapper will be called with
the async result and this mapper returns another future object. This returned future completion will complete
the future returned by this method call.
If any mapper function throws an exception, the returned future will be failed with this exception.
public <U> Future<T> eventually(Function<Void,Future<U>> mapper)
Futuremapper that will be always be called.
When this future (the one on which eventually is called) completes, the mapper will be called
and this mapper returns another future object. This returned future completion will complete the future returned
by this method call with the original result of the future.
The outcome of the future returned by the mapper will not influence the the nature
of the returned future.
eventually in interface Future<T>mapper - the function returning the future.public <U> Future<U> map(Function<T,U> mapper)
Futuremapper function on this future.
When this future succeeds, the mapper will be called with the completed value and this mapper
returns a value. This value will complete the future returned by this method call.
If the mapper throws an exception, the returned future will be failed with this exception.
When this future fails, the failure will be propagated to the returned future and the mapper
will not be called.
map in interface AsyncResult<T>map in interface Future<T>mapper - the mapper functionpublic <V> Future<V> map(V value)
Futurevalue.
When this future succeeds, this value will complete the future returned by this method call.
When this future fails, the failure will be propagated to the returned future.
map in interface AsyncResult<T>map in interface Future<T>value - the value that eventually completes the mapped futurepublic Future<T> otherwise(Function<Throwable,T> mapper)
Futuremapper function on this future.
When this future fails, the mapper will be called with the completed value and this mapper
returns a value. This value will complete the future returned by this method call.
If the mapper throws an exception, the returned future will be failed with this exception.
When this future succeeds, the result will be propagated to the returned future and the mapper
will not be called.
otherwise in interface AsyncResult<T>otherwise in interface Future<T>mapper - the mapper functionpublic Future<T> otherwise(T value)
Futurevalue.
When this future fails, this value will complete the future returned by this method call.
When this future succeeds, the result will be propagated to the returned future.
otherwise in interface AsyncResult<T>otherwise in interface Future<T>value - the value that eventually completes the mapped futureCopyright © 2021. All rights reserved.