Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add javadoc for ApiFutures #1609

Merged
merged 6 commits into from
Apr 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
revert code change
  • Loading branch information
JoeWang1127 committed Apr 5, 2023
commit 253db9abec4a22a9cf705610832efad0a2b8b66e
40 changes: 27 additions & 13 deletions api-common-java/src/main/java/com/google/api/core/ApiFutures.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public static <V, X extends Throwable> ApiFuture<V> catching(
exceptionType,
new ApiFunctionToGuavaFunction<X, V>(callback),
executor);
return new ListenableFutureToApiFuture<>(catchingFuture);
return new ListenableFutureToApiFuture<V>(catchingFuture);
}

/**
Expand All @@ -153,9 +153,12 @@ public static <V, X extends Throwable> ApiFuture<V> catchingAsync(
Futures.catchingAsync(
listenableFutureForApiFuture(input),
exceptionType,
exception -> {
ApiFuture<V> result = callback.apply(exception);
return listenableFutureForApiFuture(result);
new AsyncFunction<X, V>() {
@Override
public ListenableFuture<V> apply(X exception) throws Exception {
ApiFuture<V> result = callback.apply(exception);
return listenableFutureForApiFuture(result);
}
},
executor);
return new ListenableFutureToApiFuture<>(catchingFuture);
Expand All @@ -169,7 +172,7 @@ public static <V, X extends Throwable> ApiFuture<V> catchingAsync(
* @see Futures#immediateFuture(Object)
*/
public static <V> ApiFuture<V> immediateFuture(V value) {
return new ListenableFutureToApiFuture<>(Futures.immediateFuture(value));
return new ListenableFutureToApiFuture<>(Futures.<V>immediateFuture(value));
}

/**
Expand All @@ -180,7 +183,7 @@ public static <V> ApiFuture<V> immediateFuture(V value) {
* @see Futures#immediateFailedFuture(Throwable)
*/
public static <V> ApiFuture<V> immediateFailedFuture(Throwable throwable) {
return new ListenableFutureToApiFuture<>(Futures.immediateFailedFuture(throwable));
return new ListenableFutureToApiFuture<V>(Futures.<V>immediateFailedFuture(throwable));
}

/**
Expand All @@ -192,7 +195,7 @@ public static <V> ApiFuture<V> immediateFailedFuture(Throwable throwable) {
* @see Futures#immediateCancelledFuture()
*/
public static <V> ApiFuture<V> immediateCancelledFuture() {
return new ListenableFutureToApiFuture<>(Futures.immediateCancelledFuture());
return new ListenableFutureToApiFuture<V>(Futures.<V>immediateCancelledFuture());
}

/**
Expand Down Expand Up @@ -250,8 +253,11 @@ public static <V> ApiFuture<List<V>> allAsList(
Futures.allAsList(
Iterables.transform(
futures,
(Function<ApiFuture<? extends V>, ListenableFuture<? extends V>>)
ApiFutures::listenableFutureForApiFuture)));
new Function<ApiFuture<? extends V>, ListenableFuture<? extends V>>() {
public ListenableFuture<? extends V> apply(ApiFuture<? extends V> apiFuture) {
return listenableFutureForApiFuture(apiFuture);
}
})));
}

/**
Expand All @@ -276,8 +282,11 @@ public static <V> ApiFuture<List<V>> successfulAsList(
Futures.successfulAsList(
Iterables.transform(
futures,
(Function<ApiFuture<? extends V>, ListenableFuture<? extends V>>)
ApiFutures::listenableFutureForApiFuture)));
new Function<ApiFuture<? extends V>, ListenableFuture<? extends V>>() {
public ListenableFuture<? extends V> apply(ApiFuture<? extends V> apiFuture) {
return listenableFutureForApiFuture(apiFuture);
}
})));
}

/**
Expand Down Expand Up @@ -314,7 +323,12 @@ public static <I, O> ApiFuture<O> transformAsync(
ListenableFuture<O> listenableOutput =
Futures.transformAsync(
listenableInput,
anotherInput -> listenableFutureForApiFuture(function.apply(anotherInput)),
new AsyncFunction<I, O>() {
@Override
public ListenableFuture<O> apply(I input) throws Exception {
return listenableFutureForApiFuture(function.apply(input));
}
},
executor);
return new ListenableFutureToApiFuture<>(listenableOutput);
}
Expand All @@ -325,7 +339,7 @@ private static <V> ListenableFuture<V> listenableFutureForApiFuture(ApiFuture<V>
// prefer to use the wrapped ListenableFuture to reduce the number of layers
listenableFuture = ((AbstractApiFuture<V>) apiFuture).getInternalListenableFuture();
} else {
listenableFuture = new ApiFutureToListenableFuture<>(apiFuture);
listenableFuture = new ApiFutureToListenableFuture<V>(apiFuture);
}
return listenableFuture;
}
Expand Down