concurrent/src/main/java/io/airlift/concurrent/MoreFutures.java
@Deprecated
    public static <V> CompletableFuture<V> firstCompletedFuture(Iterable<? extends CompletionStage<? extends V>> futures, boolean propagateCancel)
    {
        requireNonNull(futures, "futures is null");
        checkArgument(!isEmpty(futures), "futures is empty");

        CompletableFuture<V> future = new CompletableFuture<>();
        for (CompletionStage<? extends V> stage : futures) {
            stage.whenComplete((value, exception) -> {
                if (exception != null) {
                    future.completeExceptionally(exception);
                }
                else {
                    future.complete(value);
                }
            });
        }
        if (propagateCancel) {
            future.exceptionally(throwable -> {
                if (throwable instanceof CancellationException) {
                    for (CompletionStage<? extends V> sourceFuture : futures) {
                        if (sourceFuture instanceof Future) {
                            ((Future<?>) sourceFuture).cancel(true);
                        }
                    }
                }
                return null;
            });
        }
        return future;
    }
@Deprecated
    public static <V> CompletableFuture<V> firstCompletedFuture(Iterable<? extends CompletionStage<? extends V>> futures, boolean propagateCancel)
    {
        requireNonNull(futures, "futures is null");
        checkArgument(!isEmpty(futures), "futures is empty");

        CompletableFuture<V> future = new CompletableFuture<>();
        for (CompletionStage<? extends V> stage : futures) {
            stage.whenComplete((value, exception) -> {
                if (exception != null) {
                    future.completeExceptionally(exception);
                }
                else {
                    future.complete(value);
                }
            });
        }
        if (propagateCancel) {
            future.exceptionally(throwable -> {
                if (throwable instanceof CancellationException) {
                    for (CompletionStage<? extends V> sourceFuture : futures) {
                        if (sourceFuture instanceof Future) {
                            ((Future<?>) sourceFuture).cancel(true);
                        }
                    }
                }
                return null;
            });
        }
        return future;
    }
@ Deprecated public static < V > CompletableFuture < V > firstCompletedFuture ( Iterable < ? extends CompletionStage < ? extends V > > futures , boolean propagateCancel ) { requireNonNull ( futures , "futures is null" ) ; checkArgument ( ! isEmpty ( futures ) , "futures is empty" ) ; CompletableFuture < V > future = new CompletableFuture <> ( ) ; for ( CompletionStage < ? extends V > stage : futures ) { stage . whenComplete ( ( value , exception ) -> { if ( exception != null ) { future . completeExceptionally ( exception ) ; } else { future . complete ( value ) ; } } ) ; } if ( propagateCancel ) { future . exceptionally ( throwable -> { if ( throwable instanceof CancellationException ) { for ( CompletionStage < ? extends V > sourceFuture : futures ) { if ( sourceFuture instanceof Future ) { ( ( Future < ? > ) sourceFuture ) . cancel ( true ) ; } } } return null ; } ) ; } return future ; }
Creates a future that completes when the first future completes either normally
or exceptionally. Cancellation of the future will optionally propagate to the
supplied futures.
Creates a future that completes when the first future completes either normally or exceptionally . Cancellation of the future will optionally propagate to the supplied futures .