Class Futures.FutureCombiner<V>
- Enclosing class:
Futures
ListenableFuture whose result is generated from a combination
of input futures.
See Futures.whenAllComplete(com.google.common.util.concurrent.ListenableFuture<? extends V>...) and Futures.whenAllSucceed(com.google.common.util.concurrent.ListenableFuture<? extends V>...) for how to instantiate this class.
Example:
final ListenableFuture<Instant> loginDateFuture =
loginService.findLastLoginDate(username);
final ListenableFuture<List<String>> recentCommandsFuture =
recentCommandsService.findRecentCommands(username);
Callable<UsageHistory> usageComputation =
new Callable<UsageHistory>() {
public UsageHistory call() throws Exception {
return new UsageHistory(
username, loginDateFuture.get(), recentCommandsFuture.get());
}
};
ListenableFuture<UsageHistory> usageFuture =
Futures.whenAllSucceed(loginDateFuture, recentCommandsFuture)
.call(usageComputation, executor);- Since:
- 20.0
-
Method Summary
Modifier and TypeMethodDescription<C> ListenableFuture<C> Likecall(Callable, Executor)but using direct executor.<C> ListenableFuture<C> Creates theListenableFuturewhich will return the result of callingCallable.call()incombinerwhen all futures complete, using the specifiedexecutor.<C> ListenableFuture<C> callAsync(AsyncCallable<C> combiner) LikecallAsync(AsyncCallable, Executor)but using direct executor.<C> ListenableFuture<C> callAsync(AsyncCallable<C> combiner, Executor executor) Creates theListenableFuturewhich will return the result of callingAsyncCallable.call()incombinerwhen all futures complete, using the specifiedexecutor.
-
Method Details
-
callAsync
Creates theListenableFuturewhich will return the result of callingAsyncCallable.call()incombinerwhen all futures complete, using the specifiedexecutor.If the combiner throws a
CancellationException, the returned future will be cancelled.If the combiner throws an
ExecutionException, the cause of the thrownExecutionExceptionwill be extracted and returned as the cause of the newExecutionExceptionthat gets thrown by the returned combined future.Canceling this future will attempt to cancel all the component futures.
-
callAsync
LikecallAsync(AsyncCallable, Executor)but using direct executor. -
call
Creates theListenableFuturewhich will return the result of callingCallable.call()incombinerwhen all futures complete, using the specifiedexecutor.If the combiner throws a
CancellationException, the returned future will be cancelled.If the combiner throws an
ExecutionException, the cause of the thrownExecutionExceptionwill be extracted and returned as the cause of the newExecutionExceptionthat gets thrown by the returned combined future.Canceling this future will attempt to cancel all the component futures.
-
call
Likecall(Callable, Executor)but using direct executor.
-