private static class Futures.ChainingListenableFuture<I,O> extends AbstractFuture<O> implements java.lang.Runnable
ListenableFuture
that also implements
Runnable
so that it can be used to nest ListenableFutures.
Once the passed-in ListenableFuture
is complete, it calls the
passed-in Function
to generate the result.
For historical reasons, this class has a special case in its exception
handling: If the given AsyncFunction
throws an UndeclaredThrowableException
, ChainingListenableFuture
unwraps it
and uses its cause as the output future's exception, rather than
using the UndeclaredThrowableException
itself as it would for other
exception types. The reason for this is that Futures.transform
used
to require a Function
, whose apply
method is not allowed to
throw checked exceptions. Nowadays, Futures.transform
has an
overload that accepts an AsyncFunction
, whose apply
method
is allowed to throw checked exception. Users who wish to throw
checked exceptions should use that overload instead, and we
should remove the UndeclaredThrowableException
special case.
AbstractFuture.Sync<V>
Modifier and Type | Field and Description |
---|---|
private AsyncFunction<? super I,? extends O> |
function |
private ListenableFuture<? extends I> |
inputFuture |
private ListenableFuture<? extends O> |
outputFuture |
Modifier | Constructor and Description |
---|---|
private |
ChainingListenableFuture(AsyncFunction<? super I,? extends O> function,
ListenableFuture<? extends I> inputFuture) |
Modifier and Type | Method and Description |
---|---|
boolean |
cancel(boolean mayInterruptIfRunning) |
private void |
cancel(java.util.concurrent.Future<?> future,
boolean mayInterruptIfRunning) |
void |
run() |
addListener, cancellationExceptionWithCause, get, get, interruptTask, isCancelled, isDone, set, setException, wasInterrupted
private AsyncFunction<? super I,? extends O> function
private ListenableFuture<? extends I> inputFuture
private volatile ListenableFuture<? extends O> outputFuture
private ChainingListenableFuture(AsyncFunction<? super I,? extends O> function, ListenableFuture<? extends I> inputFuture)
public boolean cancel(boolean mayInterruptIfRunning)
cancel
in interface java.util.concurrent.Future<O>
cancel
in class AbstractFuture<O>
private void cancel(@Nullable java.util.concurrent.Future<?> future, boolean mayInterruptIfRunning)
public void run()
run
in interface java.lang.Runnable