T - the type of the eventual value of the PartialFuturepublic interface PartialFuture<T> extends Cancellable, Disposable
PartialFuture will be set exactly once to either a "completed" T
or to an Exception. A PartialFuture is "partial" in that some
outcomes of the process involve the error output being a checked exception. A
Future is a special case of a PartialFuture that cannot result in
a checked exception.PartialFuture can be waited on by blocking, or by using asynchronous callbacks.| Modifier and Type | Method and Description |
|---|---|
void |
blockInterruptibly()
Blocks until this
Future is set to either a value or an error. |
void |
blockUntilReady()
Blocks until this
Future is set to either a value or an error. |
void |
cancel()
Cancels this asynchronous operation.
|
void |
dispose()
Equivalent to calling
cancel(). |
<V> PartialFuture<V> |
flatMap(PartialFunction<? super T,? extends PartialFuture<V>> m)
Applies the successful result of this operation as the input into another asynchronous
operation and returns a handle to that result.
|
T |
get()
Blocks until a value is set on this
PartialFuture and returns it. |
Throwable |
getError()
Gets the error from a
Future if it has been set to this state. |
T |
getInterruptibly()
Blocks until a value is set on this
PartialFuture and returns it. |
boolean |
isDone()
Gets the readiness of this
Future. |
boolean |
isError()
Tests if this
Future is set to an error |
<V> PartialFuture<V> |
map(PartialFunction<? super T,V> m)
Apply a function to the successful result of this operation.
|
void |
onReady(Runnable r)
Registers a
Runnable to run as the callback for this Future
on a default thread. |
boolean |
onReadyAlready(Runnable r)
Checks if this
Future is ready and, if not, atomically registers a
Runnable to run as the callback for this future on a default thread. |
Future<T> |
rescue(Function<? super Exception,Future<T>> m)
Convert an error output of this operation into another asynchronous process.
|
PartialFuture<T> |
rescue(PartialFunction<? super Exception,? extends PartialFuture<T>> m)
Map any error result of this
Future to another asynchronous process. |
void onReady(Runnable r)
Runnable to run as the callback for this Future
on a default thread. It will be called after the future becomes ready, including
if the future is set to a value, set to an error, or cancelled.map(PartialFunction) and flatMap(PartialFunction)
instead, as they automatically provide error propagation and cancellation.r - the code to run when the future is set either to value or errorboolean onReadyAlready(Runnable r)
Future is ready and, if not, atomically registers a
Runnable to run as the callback for this future on a default thread. The
callback will not be called if the future is ready. Callers can rely on the guarantee
that if this function returns false their callback will be executed on
completion (including if the future is set to a value, set to an error, or cancelled),
and if true they can then call get() without blocking.r - the code to run when the future is set if it is not currently readytrue if the future is ready, false otherwise<V> PartialFuture<V> map(PartialFunction<? super T,V> m)
Future.Future is cancelled the input
input Future will also be cancelled.m - the map to the conversion to be runFuture that passes errors and converts output of this Future.<V> PartialFuture<V> flatMap(PartialFunction<? super T,? extends PartialFuture<V>> m)
Future is complete and a result
is returned, the Mapper m is invoked to begin a new asynchronous process
using the result.
Errors in the execution of either operation are sent to the resulting Future.Future is cancelled the input
input Future will also be cancelled.m - the map to the asynchronous process to be runFuture that passes errors and converts output of this Future
to the output of another asynchronous process.PartialFuture<T> rescue(PartialFunction<? super Exception,? extends PartialFuture<T>> m)
Future to another asynchronous process. This can be
used when an error is expected or can be logically dealt with in some way. If the
rescue process cannot handle the error, or if the rescue process itself throws an error,
that error will be set on this Future. If the result
of this call is used in place of this Future, the user of the output
Future
will see successes of this process, successes of the rescue process, or errors from
the rescue process.m - the process to run that maps an error into another asynchronous operationFuture with modified error behaviorFuture<T> rescue(Function<? super Exception,Future<T>> m)
m - the process to run on completion into error state.Future output with modified error behaviorvoid blockUntilReady()
Future is set to either a value or an error.
When this function returns without an error, isDone() will return
true.
void blockInterruptibly()
throws InterruptedException
Future is set to either a value or an error.
When this function returns without an error, isDone() will return
true.
InterruptedException - if the blocked thread is interruptedT get() throws Exception
PartialFuture and returns it.
If this PartialFuture is set to an Exception or Error
this call will throw that error.Exception - if the process was not successfully executed.InterruptedException - if the blocked thread is interruptedError - if the process encountered a serious Error during execution.T getInterruptibly() throws Exception
PartialFuture and returns it.
If this PartialFuture is set to an Exception or Error
this call will throw that error.Exception - if the process was not successfully executed.InterruptedException - if the blocked thread is interruptedError - if the process encountered a serious Error during execution.void cancel()
Future is
ready, subsequent attempts to access its value will throw.
Cancelling a Future which is already set has no effect.
Cancelling a Future should not be assumed to eliminate the affects
of launching the operation. Many asynchronous operations start work on remote
machines -- this work will generally not be stopped if the local Future
is cancelled.cancel in interface Cancellableboolean isDone()
Future. A Future is ready
if the value has been set or an error has been set.true if the Future is set to a value or errorboolean isError()
Future is set to an errortrue if in error state, false otherwiseThrowable getError()
Future if it has been set to this state. If
this Future is not yet set, or has not been set to an error, throws
an exception. Although this method returns a Throwable, the set of
possible types is more limited. A PartialFuture is limited to be set in
an error state to an Exception (or a subclass thereof) or an unchecked
Error.FutureIllegalStateException - if this PartialFuture is not in an error statevoid dispose()
cancel().dispose in interface Disposable