This repository was archived by the owner on Sep 27, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
main/java/com/google/api/core
test/java/com/google/api/core Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -172,6 +172,21 @@ public ListenableFuture<? extends V> apply(ApiFuture<? extends V> apiFuture) {
172172 }
173173 })));
174174 }
175+
176+ @ BetaApi
177+ public static <V > ApiFuture <List <V >> successfulAsList (
178+ Iterable <? extends ApiFuture <? extends V >> futures ) {
179+ return new ListenableFutureToApiFuture <>(
180+ Futures .successfulAsList (
181+ Iterables .transform (
182+ futures ,
183+ new Function <ApiFuture <? extends V >, ListenableFuture <? extends V >>() {
184+ public ListenableFuture <? extends V > apply (ApiFuture <? extends V > apiFuture ) {
185+ return listenableFutureForApiFuture (apiFuture );
186+ }
187+ })));
188+ }
189+
175190 /*
176191 * @deprecated Use {@linkplain #transformAsync(ApiFuture, ApiFunction, Executor) the
177192 * overload that requires an executor}. For identical behavior, pass {@link
Original file line number Diff line number Diff line change @@ -154,6 +154,17 @@ public void testAllAsList() throws Exception {
154154 assertThat (listFuture .get ()).containsExactly (1 , 2 ).inOrder ();
155155 }
156156
157+ @ Test
158+ public void successfulAllAsList () throws Exception {
159+ SettableApiFuture <Integer > inputFuture1 = SettableApiFuture .<Integer >create ();
160+ SettableApiFuture <Integer > inputFuture2 = SettableApiFuture .<Integer >create ();
161+ ApiFuture <List <Integer >> listFuture =
162+ ApiFutures .successfulAsList (ImmutableList .of (inputFuture1 , inputFuture2 ));
163+ inputFuture1 .set (1 );
164+ inputFuture2 .setException (new Exception ());
165+ assertThat (listFuture .get ()).containsExactly (1 , null ).inOrder ();
166+ }
167+
157168 @ Test
158169 public void testTransformAsync () throws Exception {
159170 ApiFuture <Integer > inputFuture = ApiFutures .immediateFuture (0 );
You can’t perform that action at this time.
0 commit comments