Class SucceededFuture<T>
- All Implemented Interfaces:
AsyncResult<T>
,Future<T>
,FutureInternal<T>
- Author:
- Julien Viet
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SucceededFuture
Stateless instance of empty results that can be shared safely. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(Listener<T> listener) Add a listener to the future result.cause()
A Throwable describing failure.<U> Future<U>
Compose this future with asuccessMapper
andfailureMapper
functions.protected final void
emitFailure
(Throwable cause, Listener<T> listener) protected final void
emitSuccess
(T value, Listener<T> listener) Create a future that hasn't completed yeteventually
(Function<Void, Future<U>> mapper) Compose this future with afunction
that will be always be called.boolean
failed()
Did it fail?boolean
Create a future that has already succeeded<U> Future<U>
Apply amapper
function on this future.<V> Future<V>
map
(V value) Map the result of a future to a specificvalue
.onComplete
(Handler<AsyncResult<T>> handler) Add a handler to be notified of the result.Add a handler to be notified of the failed result.Add a handler to be notified of the succeeded result.Apply amapper
function on this future.Map the failure of a future to a specificvalue
.void
removeListener
(Listener<T> listener) Remove a listener to the future result.result()
The result of the operation.boolean
Did it succeed?toString()
<U> Future<U>
transform
(Function<AsyncResult<T>, Future<U>> mapper) Transform this future with amapper
functions.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface dev.webfx.platform.async.Future
andThen, compose, eventually, flatMap, mapEmpty, onComplete, otherwiseEmpty, recover
-
Field Details
-
EMPTY
Stateless instance of empty results that can be shared safely.
-
-
Constructor Details
-
SucceededFuture
Create a future that has already succeeded- Parameters:
result
- the result
-
-
Method Details
-
isComplete
public boolean isComplete()Create a future that has already succeeded- Parameters:
context
- the contextresult
- the result- Returns:
- true if completed, false if not
-
onSuccess
Description copied from interface:Future
Add a handler to be notified of the succeeded result.WARNING: this is a terminal operation. If several
handler
s are registered, there is no guarantee that they will be invoked in order of registration.- Parameters:
handler
- the handler that will be called with the succeeded result- Returns:
- a reference to this, so it can be used fluently
-
onFailure
Description copied from interface:Future
Add a handler to be notified of the failed result.WARNING: this is a terminal operation. If several
handler
s are registered, there is no guarantee that they will be invoked in order of registration.- Parameters:
handler
- the handler that will be called with the failed result- Returns:
- a reference to this, so it can be used fluently
-
onComplete
Description copied from interface:Future
Add a handler to be notified of the result.WARNING: this is a terminal operation. If several
handler
s are registered, there is no guarantee that they will be invoked in order of registration.- Parameters:
handler
- the handler that will be called with the result- Returns:
- a reference to this, so it can be used fluently
-
addListener
Description copied from interface:FutureInternal
Add a listener to the future result.- Parameters:
listener
- the listener
-
removeListener
Description copied from interface:FutureInternal
Remove a listener to the future result.- Parameters:
listener
- the listener
-
result
Description copied from interface:Future
The result of the operation. This will be null if the operation failed.- Returns:
- the result or null if the operation failed.
-
cause
Description copied from interface:Future
A Throwable describing failure. This will be null if the operation succeeded.- Returns:
- the cause or null if the operation succeeded.
-
succeeded
public boolean succeeded()Description copied from interface:Future
Did it succeed?- Returns:
- true if it succeded or false otherwise
-
failed
public boolean failed()Description copied from interface:Future
Did it fail?- Returns:
- true if it failed or false otherwise
-
map
Description copied from interface:Future
Map the result of a future to a specificvalue
.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.
-
otherwise
Description copied from interface:Future
Apply amapper
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
Description copied from interface:Future
Map the failure of a future to a specificvalue
.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.
-
toString
-
emitSuccess
Create a future that hasn't completed yet -
emitFailure
-
compose
public <U> Future<U> compose(Function<T, Future<U>> successMapper, Function<Throwable, Future<U>> failureMapper) Description copied from interface:Future
Compose this future with asuccessMapper
andfailureMapper
functions.When this future (the one on which
compose
is called) succeeds, thesuccessMapper
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, thefailureMapper
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.
-
transform
Description copied from interface:Future
Transform this future with amapper
functions.When this future (the one on which
transform
is called) completes, themapper
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.
-
eventually
Description copied from interface:Future
Compose this future with afunction
that will be always be called.When this future (the one on which
eventually
is called) completes, thefunction
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
function
will not influence the nature of the returned future.- Specified by:
eventually
in interfaceFuture<T>
- Parameters:
mapper
- the function returning the future.- Returns:
- the composed future
-
map
Description copied from interface:Future
Apply amapper
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.- Specified by:
map
in interfaceAsyncResult<T>
- Specified by:
map
in interfaceFuture<T>
- Parameters:
mapper
- the mapper function- Returns:
- the mapped future
-