@@ -195,11 +195,6 @@ public CompletableFuture<List<T>> await(@Nullable CompletableFuture<Void> cancel
195195 return CompletableFuture .completedFuture (Collections .singletonList ((T ) value ));
196196 }
197197
198- @ Override
199- public CompletableFuture <List <T >> await (@ Nullable CompletableFuture <Void > cancellationFuture ) {
200- return await ();
201- }
202-
203198 @ Override
204199 public Object awaitPolymorphic () {
205200 commonSizeAssert ();
@@ -328,52 +323,6 @@ private List<T> harvestResults(Object[] array) {
328323 return results ;
329324 }
330325
331- @ SuppressWarnings ("unchecked" )
332- @ Override
333- public CompletableFuture <List <T >> await (@ Nullable CompletableFuture <Void > cancellationFuture ) {
334- commonSizeAssert ();
335- if (cfCount == 0 ) {
336- return CompletableFuture .completedFuture (materialisedList (array ));
337- }
338- if (cancellationFuture == null ) {
339- return await ();
340- }
341-
342- CompletableFuture <List <T >> overallResult = new CompletableFuture <>();
343- CompletableFuture <Void > allOf = CompletableFuture .allOf (copyOnlyCFsToArray ());
344-
345- // Race "all field futures complete" against cancellation. The cancellation future always
346- // completes normally (see ExecutionInput#cancel), so anyOf can only complete exceptionally
347- // when a field future fails - in which case we propagate that failure.
348- CompletableFuture .anyOf (allOf , cancellationFuture ).whenComplete ((ignored , exception ) -> {
349- if (exception != null ) {
350- overallResult .completeExceptionally (exception );
351- return ;
352- }
353- // Either every field future is done (allOf won) or cancellation won the race. In both
354- // cases we harvest whatever has completed; field futures that are not yet done become
355- // null. join() is safe here: if allOf is not done then no field future has failed (a
356- // failure would have completed allOf exceptionally and taken the branch above).
357- overallResult .complete (harvestResults (array ));
358- });
359-
360- return overallResult ;
361- }
362-
363- @ SuppressWarnings ("unchecked" )
364- private List <T > harvestResults (Object [] array ) {
365- List <T > results = new ArrayList <>(array .length );
366- for (Object object : array ) {
367- if (object instanceof CompletableFuture ) {
368- CompletableFuture <T > cf = (CompletableFuture <T >) object ;
369- results .add (cf .isDone () ? cf .join () : null );
370- } else {
371- results .add ((T ) object );
372- }
373- }
374- return results ;
375- }
376-
377326 @ SuppressWarnings ("unchecked" )
378327 @ NonNull
379328 private CompletableFuture <T >[] copyOnlyCFsToArray () {
0 commit comments