public interface RedFuture
Future
like interface,
which supports trivial, fully asynchronous, Java 8 callbacks.
As opposed to RedFutureOf
, this interface represents a future that is not
pending value, but only resolved to mark the underlying task complete.Modifier and Type | Method and Description |
---|---|
RedFuture |
addFailureCallback(Callback<Throwable> callback)
Attach a callback receiving a throwable to be invoked when the future is failed.
|
RedFuture |
addFailureCallback(Executor executor,
Callback<Throwable> callback)
Attach a callback receiving a throwable to be invoked when the future is failed.
|
RedFuture |
addFinallyCallback(EmptyCallback callback)
Attach a no-parameter callback to be invoked when the future is either successfully
resolved, or otherwise failed, in resemblance to java finally block.
|
RedFuture |
addFinallyCallback(Executor executor,
EmptyCallback callback)
Attach a no-parameter callback to be invoked when the future is either successfully
resolved, or otherwise failed, in resemblance to java finally block.
|
RedFuture |
addSuccessCallback(EmptyCallback callback)
Attach a no-parameter callback to be invoked when the future is successfully resolved.
|
RedFuture |
addSuccessCallback(Executor executor,
EmptyCallback callback)
Attach a no-parameter callback to be invoked when the future is successfully resolved.
|
static <T> RedFutureOf<T> |
convert(Future<T> future)
|
static <T> RedFutureOf<T> |
convert(Future<T> future,
Executor executor)
|
static RedFuture |
failed(Throwable t) |
static <T> RedFutureOf<T> |
failedOf(Throwable t) |
static OpenRedFuture |
future() |
static <T> OpenRedFutureOf<T> |
futureOf() |
com.google.common.util.concurrent.ListenableFuture<?> |
getListenableFuture() |
static RedFutureHub |
hub() |
boolean |
isDone()
Test to see whether or not the future is currently completed, either by success
or failure.
|
static RedFuture |
resolved() |
static <T> RedFutureOf<T> |
resolvedOf(T value) |
void |
waitForCompletion()
Tries to blocks the thread until the future is completed.
|
void |
waitForCompletion(long timeout,
TimeUnit unit)
Tries to blocks the thread for at most the given timeout until the future is completed.
|
RedFuture addSuccessCallback(EmptyCallback callback)
callback
- callback to be invoked when the future is successfully resolvedRedFuture addSuccessCallback(Executor executor, EmptyCallback callback)
executor
- executor to invoke the callbackcallback
- callback to be invoked when the future is successfully resolvedRedFuture addFailureCallback(Callback<Throwable> callback)
callback
- callback receiving a throwable to be invoked when the future is failedRedFuture addFailureCallback(Executor executor, Callback<Throwable> callback)
executor
- executor to invoke the callbackcallback
- callback receiving a throwable to be invoked when the future is failedRedFuture addFinallyCallback(EmptyCallback callback)
callback
- callback to be invoked when the future completesRedFuture addFinallyCallback(Executor executor, EmptyCallback callback)
executor
- executor to invoke the callbackcallback
- callback to be invoked when the future completesboolean isDone()
void waitForCompletion() throws ExecutionException, InterruptedException
ExecutionException
- if the computation threw an exceptionInterruptedException
- if the current thread was interrupted while waitingFuture.get()
void waitForCompletion(long timeout, TimeUnit unit) throws ExecutionException, InterruptedException, TimeoutException
timeout
- the maximum time to waitunit
- the time unit of the timeout argumentExecutionException
- if the computation threw an exceptionInterruptedException
- if the current thread was interrupted while waitingTimeoutException
- if the wait timed outFuture.get(long, TimeUnit)
com.google.common.util.concurrent.ListenableFuture<?> getListenableFuture()
ListenableFuture
static OpenRedFuture future()
OpenRedFuture
static <T> OpenRedFutureOf<T> futureOf()
T
- type of the future valueOpenRedFutureOf
static RedFuture resolved()
OpenRedFuture
which is already resolvedstatic <T> RedFutureOf<T> resolvedOf(T value)
T
- type of the future valuevalue
- to be resolved withOpenRedFutureOf
which is already resolved with given valuestatic RedFuture failed(Throwable t)
t
- to fail the future withOpenRedFuture
which is already failed with given throwablestatic <T> RedFutureOf<T> failedOf(Throwable t)
T
- type of the future valuet
- to fail the future withOpenRedFutureOf
which is already failed with given throwablestatic <T> RedFutureOf<T> convert(Future<T> future)
Future
object to a RedFuture
see JdkFutureAdapters.listenInPoolThread(Future)
for detailed implicationsT
- type of the future valuefuture
- future to convertFuture
static <T> RedFutureOf<T> convert(Future<T> future, Executor executor)
Future
object to a RedFuture
with given executor
see JdkFutureAdapters.listenInPoolThread(Future, Executor)
for detailed implicationsT
- type of the future valuefuture
- future to convertexecutor
- executor to wait to future to complete and then execute callbacks
note that if the future is already completed, the callbacks will be
executed by the current threadFuture
static RedFutureHub hub()
RedFutureHub
Copyright © 2017. All rights reserved.