Skip to content

Commit

Permalink
Call Futures.transform with an explicit executor because it is the pr…
Browse files Browse the repository at this point in the history
…eferred style.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=149582781
  • Loading branch information
gk5885 authored and ronshapiro committed Mar 9, 2017
1 parent f33658e commit 6afff2c
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.google.common.base.Function;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.CodeBlock;
import com.squareup.javapoet.FieldSpec;
Expand All @@ -53,6 +54,7 @@
import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.Executor;
import javax.inject.Provider;

/** The nested class and static methods required by the component to implement optional bindings. */
Expand Down Expand Up @@ -324,15 +326,16 @@ private TypeSpec presentOptionalFactoryClass(PresentFactorySpec spec) {
}

/**
* An expression that uses {@link Futures#transform(ListenableFuture, Function)} to transform a
* {@code ListenableFuture<inputType>} into a {@code ListenableFuture<Optional<inputType>>}.
* An expression that uses {@link Futures#transform(ListenableFuture, Function, Executor)} to
* transform a {@code ListenableFuture<inputType>} into a {@code
* ListenableFuture<Optional<inputType>>}.
*
* @param inputFuture an expression of type {@code ListenableFuture<inputType>}
*/
private static CodeBlock transformFutureToOptional(
OptionalKind optionalKind, TypeName inputType, CodeBlock inputFuture) {
return CodeBlock.of(
"$T.transform($L, $L)",
"$T.transform($L, $L, $T.directExecutor())",
Futures.class,
inputFuture,
anonymousClassBuilder("")
Expand All @@ -347,7 +350,8 @@ private static CodeBlock transformFutureToOptional(
.addParameter(inputType, "input")
.addCode("return $L;", optionalKind.presentExpression(CodeBlock.of("input")))
.build())
.build());
.build(),
MoreExecutors.class);
}

/**
Expand Down

0 comments on commit 6afff2c

Please sign in to comment.