public class RPromise<T> extends RFuture<T>
RFuture
that can be updated with a success or failure
result when it becomes available.
This implementation also guarantees a useful behavior, which is that all listeners added prior to the completion of the promise will be cleared when the promise is completed, and no further listeners will be retained. This allows the promise to be retained after is has been completed as a useful "box" for its underlying value, without concern that references to long satisfied listeners will be inadvertently retained.
RFuture.T2<A,B>, RFuture.T3<A,B,C>
Reactor.RListener
Constructor and Description |
---|
RPromise() |
Modifier and Type | Method and Description |
---|---|
void |
complete(Try<T> result)
Causes this promise to be completed with
result . |
Slot<Try<T>> |
completer()
Returns a slot that can be used to complete this promise.
|
static <T> RPromise<T> |
create()
Creates a new, uncompleted, promise.
|
void |
fail(Throwable cause)
Causes this promise to be completed with failure caused by
cause . |
Slot<Throwable> |
failer()
Returns a slot that can be used to
fail(java.lang.Throwable) this promise. |
Try<T> |
result()
Returns the result of this future, or null if it is not yet complete.
|
void |
succeed(T value)
Causes this promise to be completed successfully with
value . |
Slot<T> |
succeeder()
Returns a slot that can be used to
succeed(T) this promise. |
bindComplete, collect, failure, flatMap, isComplete, isCompleteNow, map, onComplete, onFailure, onSuccess, recover, result, sequence, sequence, sequence, success, success, transform
clearConnections, hasConnections
public static <T> RPromise<T> create()
public void succeed(T value)
value
.public void fail(Throwable cause)
cause
.public Slot<T> succeeder()
succeed(T)
this promise.public Slot<Throwable> failer()
fail(java.lang.Throwable)
this promise.public Try<T> result()
RFuture
NOTE: don't use this method! You should wire up reactions to the completion of
this future via RFuture.onSuccess(react.SignalView.Listener<? super T>)
or RFuture.onFailure(react.SignalView.Listener<? super java.lang.Throwable>)
. React is not a blocking async
library where on might block a calling thread on the result of a future and then obtain the
result synchronously. This is only appropriate when you're trying to abstract over
synchronous and asynchronous variants of a computation, and you want to use the future
machinery in both cases, but in the synchronous case you know that your future will be
complete by the time you want to obtain its result.
Copyright © 2017. All rights reserved.