- java.lang.Object
-
- com.google.common.util.concurrent.ClosingFuture.Combiner
-
- com.google.common.util.concurrent.ClosingFuture.Combiner2<V1,V2>
-
- Type Parameters:
V1
- the type returned by the first futureV2
- the type returned by the second future
- Enclosing class:
- ClosingFuture<V extends @Nullable Object>
public static final class ClosingFuture.Combiner2<V1 extends @Nullable Object,V2 extends @Nullable Object> extends ClosingFuture.Combiner
A genericClosingFuture.Combiner
that lets you use a lambda or method reference to combine twoClosingFuture
s. UseClosingFuture.whenAllSucceed(ClosingFuture, ClosingFuture)
to start this combination.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ClosingFuture.Combiner2.AsyncClosingFunction2<V1 extends @Nullable Object,V2 extends @Nullable Object,U extends @Nullable Object>
A function that returns aClosingFuture
when applied to the values of the two futures passed toClosingFuture.whenAllSucceed(ClosingFuture, ClosingFuture)
.static interface
ClosingFuture.Combiner2.ClosingFunction2<V1 extends @Nullable Object,V2 extends @Nullable Object,U extends @Nullable Object>
A function that returns a value when applied to the values of the two futures passed toClosingFuture.whenAllSucceed(ClosingFuture, ClosingFuture)
.-
Nested classes/interfaces inherited from class com.google.common.util.concurrent.ClosingFuture.Combiner
ClosingFuture.Combiner.AsyncCombiningCallable<V extends @Nullable Object>, ClosingFuture.Combiner.CombiningCallable<V extends @Nullable Object>
-
-
Field Summary
-
Fields inherited from class com.google.common.util.concurrent.ClosingFuture.Combiner
inputs
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <U extends @Nullable Object>
ClosingFuture<U>call(ClosingFuture.Combiner2.ClosingFunction2<V1,V2,U> function, Executor executor)
Returns a newClosingFuture
pipeline step derived from the inputs by applying a combining function to their values.<U extends @Nullable Object>
ClosingFuture<U>callAsync(ClosingFuture.Combiner2.AsyncClosingFunction2<V1,V2,U> function, Executor executor)
Returns a newClosingFuture
pipeline step derived from the inputs by applying aClosingFuture
-returning function to their values.-
Methods inherited from class com.google.common.util.concurrent.ClosingFuture.Combiner
call, callAsync
-
-
-
-
Method Detail
-
call
public <U extends @Nullable Object> ClosingFuture<U> call(ClosingFuture.Combiner2.ClosingFunction2<V1,V2,U> function, Executor executor)
Returns a newClosingFuture
pipeline step derived from the inputs by applying a combining function to their values. The function can use aClosingFuture.DeferredCloser
to capture objects to be closed when the pipeline is done.If this combiner was returned by
ClosingFuture.whenAllSucceed(ClosingFuture, ClosingFuture)
and any of the inputs fail, so will the returned step.If the function throws a
CancellationException
, the pipeline will be cancelled.If the function throws an
ExecutionException
, the cause of the thrownExecutionException
will be extracted and used as the failure of the derived step.
-
callAsync
public <U extends @Nullable Object> ClosingFuture<U> callAsync(ClosingFuture.Combiner2.AsyncClosingFunction2<V1,V2,U> function, Executor executor)
Returns a newClosingFuture
pipeline step derived from the inputs by applying aClosingFuture
-returning function to their values. The function can use aClosingFuture.DeferredCloser
to capture objects to be closed when the pipeline is done (other than those captured by the returnedClosingFuture
).If this combiner was returned by
ClosingFuture.whenAllSucceed(ClosingFuture, ClosingFuture)
and any of the inputs fail, so will the returned step.If the function throws a
CancellationException
, the pipeline will be cancelled.If the function throws an
ExecutionException
, the cause of the thrownExecutionException
will be extracted and used as the failure of the derived step.If the function throws any other exception, it will be used as the failure of the derived step.
If an exception is thrown after the function creates a
ClosingFuture
, then none of the closeable objects in thatClosingFuture
will be closed.Usage guidelines for this method:
- Use this method only when calling an API that returns a
ListenableFuture
or aClosingFuture
. If possible, prefer callingClosingFuture.Combiner.call(CombiningCallable, Executor)
instead, with a function that returns the next value directly. - Call
closer.eventuallyClose()
for every closeable object this step creates in order to capture it for later closing. - Return a
ClosingFuture
. To turn aListenableFuture
into aClosingFuture
callClosingFuture.from(ListenableFuture)
.
The same warnings about doing heavyweight operations within
ClosingFuture.transformAsync(AsyncClosingFunction, Executor)
apply here. - Use this method only when calling an API that returns a
-
-