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);
ListenableFuture<UsageHistory> usageFuture =
Futures.whenAllSucceed(loginDateFuture, recentCommandsFuture)
.call(
() ->
new UsageHistory(
username,
Futures.getDone(loginDateFuture),
Futures.getDone(recentCommandsFuture)),
executor);
- Since:
- 20.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final boolean
private final ImmutableList
<ListenableFuture<? extends V>> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
FutureCombiner
(boolean allMustSucceed, ImmutableList<ListenableFuture<? extends V>> futures) -
Method Summary
Modifier and TypeMethodDescription<C> ListenableFuture
<C> Creates theListenableFuture
which will return the result of callingCallable.call()
incombiner
when all futures complete, using the specifiedexecutor
.<C> ListenableFuture
<C> callAsync
(AsyncCallable<C> combiner, Executor executor) Creates theListenableFuture
which will return the result of callingAsyncCallable.call()
incombiner
when all futures complete, using the specifiedexecutor
.Creates theListenableFuture
which will return the result of runningcombiner
when all Futures complete.
-
Field Details
-
allMustSucceed
private final boolean allMustSucceed -
futures
-
-
Constructor Details
-
FutureCombiner
private FutureCombiner(boolean allMustSucceed, ImmutableList<ListenableFuture<? extends V>> futures)
-
-
Method Details
-
callAsync
Creates theListenableFuture
which will return the result of callingAsyncCallable.call()
incombiner
when 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 thrownExecutionException
will be extracted and returned as the cause of the newExecutionException
that gets thrown by the returned combined future.Canceling this future will attempt to cancel all the component futures.
- Returns:
- a future whose result is based on
combiner
(or based on the input futures passed towhenAllSucceed
, if that is the method you used to create thisFutureCombiner
). Even if you don't care about the value of the future, you should typically check whether it failed: See https://errorprone.info/bugpattern/FutureReturnValueIgnored.
-
call
Creates theListenableFuture
which will return the result of callingCallable.call()
incombiner
when 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 thrownExecutionException
will be extracted and returned as the cause of the newExecutionException
that gets thrown by the returned combined future.Canceling this future will attempt to cancel all the component futures.
- Returns:
- a future whose result is based on
combiner
(or based on the input futures passed towhenAllSucceed
, if that is the method you used to create thisFutureCombiner
). Even if you don't care about the value of the future, you should typically check whether it failed: See https://errorprone.info/bugpattern/FutureReturnValueIgnored.
-
run
Creates theListenableFuture
which will return the result of runningcombiner
when all Futures complete.combiner
will run usingexecutor
.If the combiner throws a
CancellationException
, the returned future will be cancelled.Canceling this Future will attempt to cancel all the component futures.
- Returns:
- a future whose result is based on
combiner
(or based on the input futures passed towhenAllSucceed
, if that is the method you used to create thisFutureCombiner
). Even though the future never produces a value other thannull
, you should typically check whether it failed: See https://errorprone.info/bugpattern/FutureReturnValueIgnored. - Since:
- 23.6
-