diff --git a/src/main/java/com/google/api/core/ApiFutures.java b/src/main/java/com/google/api/core/ApiFutures.java index d02892619..e25170fea 100644 --- a/src/main/java/com/google/api/core/ApiFutures.java +++ b/src/main/java/com/google/api/core/ApiFutures.java @@ -172,6 +172,21 @@ public ListenableFuture apply(ApiFuture apiFuture) { } }))); } + + @BetaApi + public static ApiFuture> successfulAsList( + Iterable> futures) { + return new ListenableFutureToApiFuture<>( + Futures.successfulAsList( + Iterables.transform( + futures, + new Function, ListenableFuture>() { + public ListenableFuture apply(ApiFuture apiFuture) { + return listenableFutureForApiFuture(apiFuture); + } + }))); + } + /* * @deprecated Use {@linkplain #transformAsync(ApiFuture, ApiFunction, Executor) the * overload that requires an executor}. For identical behavior, pass {@link diff --git a/src/test/java/com/google/api/core/ApiFuturesTest.java b/src/test/java/com/google/api/core/ApiFuturesTest.java index de10b7ee8..c726bf278 100644 --- a/src/test/java/com/google/api/core/ApiFuturesTest.java +++ b/src/test/java/com/google/api/core/ApiFuturesTest.java @@ -154,6 +154,17 @@ public void testAllAsList() throws Exception { assertThat(listFuture.get()).containsExactly(1, 2).inOrder(); } + @Test + public void successfulAllAsList() throws Exception { + SettableApiFuture inputFuture1 = SettableApiFuture.create(); + SettableApiFuture inputFuture2 = SettableApiFuture.create(); + ApiFuture> listFuture = + ApiFutures.successfulAsList(ImmutableList.of(inputFuture1, inputFuture2)); + inputFuture1.set(1); + inputFuture2.setException(new Exception()); + assertThat(listFuture.get()).containsExactly(1, null).inOrder(); + } + @Test public void testTransformAsync() throws Exception { ApiFuture inputFuture = ApiFutures.immediateFuture(0);