Returns a new Future that, when any of the given Futures complete normally.
If all of the given Futures complete exceptionally, then the returned Future also does so.

@param cfs
@return
349912
public static <T> ContinuableFuture<T> anyOf(final Collection<? extends Future<? extends T>> cfs) {
        return anyOf2(cfs);
    }
418080
public <N> CompletableFutureQueue<T, N> thenCombineAsyncFromArray(Function<R, N>[] nextTransformations) {
    CompletableFutureQueue cfq = this;
    for (Function<R, N> nextTransformation : nextTransformations) {
      cfq = cfq.thenCombineAsync(nextTransformation);
    }
    return cfq;
  }
1279221
public static <T> Future<T> ofError(final Throwable error) {
        final CompletableFuture<T> cf = new CompletableFuture<>();
        cf.completeExceptionally(error);

        return Future.<T> of(cf);
    }
966363
function(futures) {
		this.resolve(function(err) {
			if (!err) {
				return;
			}
			if (futures instanceof Array) {
				for (var ii = 0; ii < futures.length; ++ii) {
					futures[ii].throw(err);
				}
			} else {
				futures.throw(err);
			}
		});
		return this;
	}
791742
public Future<T> asyncRun()
	{
		final Thread t = new Thread(this);
		{
			t.setName("AsyncRun for " + this);
			t.setDaemon(true);
			t.start();
		}

		return this;
	}
734887
public <G,B> OrFuture<G, B> goodFuture(G good) {
    return this.<G, B>promise().success(good).future();
  }
131005
public List<Future<?>> submitBackground(final ColumnFamilyStore cfs)
    {
        if (cfs.isAutoCompactionDisabled())
        {
            logger.debug("Autocompaction is disabled");
            return Collections.emptyList();
        }

        int count = compactingCF.count(cfs);
        if (count > 0 && executor.getActiveCount() >= executor.getMaximumPoolSize())
        {
            logger.debug("Background compaction is still running for {}.{} ({} remaining). Skipping",
                         cfs.keyspace.getName(), cfs.name, count);
            return Collections.emptyList();
        }

        logger.debug("Scheduling a background task check for {}.{} with {}",
                     cfs.keyspace.getName(),
                     cfs.name,
                     cfs.getCompactionStrategy().getName());
        List<Future<?>> futures = new ArrayList<Future<?>>();
        // we must schedule it at least once, otherwise compaction will stop for a CF until next flush
        do {
            if (executor.isShutdown())
            {
                logger.info("Executor has shut down, not submitting background task");
                return Collections.emptyList();
            }
            compactingCF.add(cfs);
            futures.add(executor.submit(new BackgroundCompactionTask(cfs)));
            // if we have room for more compactions, then fill up executor
        } while (executor.getActiveCount() + futures.size() < executor.getMaximumPoolSize());

        return futures;
    }
1269465
@SuppressWarnings("unchecked")
    public CompletableFuture<Void> close() {

        this.closed = true;

        List<CompletableFuture<Void>> futures = new ArrayList<>();

        forEach((connectionKey, closeable) -> {

            futures.add(closeable.closeAsync());
            connections.remove(connectionKey);
        });

        return Futures.allOf(futures);
    }
416117
public static BindFuture combineFutures(BindFuture future1, BindFuture future2) {
        if (future1 == null || future1.isBound()) {
            return future2;
        }
        else if (future2 == null || future2.isBound()) {
            return future1;
        }
        else {
            return new CompositeBindFuture(Arrays.asList(future1, future2));
        }
    }
708802
@Override
    public Future<M> getDataFuture() {
        try {
            return FutureProcessor.completedFuture(getData());
        } catch (NotAvailableException ex) {
            CompletableFuture future = new CompletableFuture();
            future.completeExceptionally(ex);
            return future;
        }
    }
414977
public static <T> CompletableFuture<T> orderedFuture(CompletableFuture<T> future) {
    CompletableFuture<T> newFuture = new OrderedFuture<>();
    future.whenComplete((r, e) -> {
      if (e == null) {
        newFuture.complete(r);
      } else {
        newFuture.completeExceptionally(e);
      }
    });
    return newFuture;
  }
71338
public Promise getNext() {
        while( !lock.compareAndSet(false,true) ) {}
        try {
            if (nextFuture == null)
                return new Promise();
            else
                return (Promise) nextFuture;
        } finally {
            lock.set(false);
        }
    }
1310912
public static <T, U extends T> CompletableFuture<T> toJava(Future<U> scalaFuture) {
		final CompletableFuture<T> result = new CompletableFuture<>();

		scalaFuture.onComplete(new OnComplete<U>() {
			@Override
			public void onComplete(Throwable failure, U success) {
				if (failure != null) {
					result.completeExceptionally(failure);
				} else {
					result.complete(success);
				}
			}
		}, Executors.directExecutionContext());

		return result;
	}
1096031
public <T> void register(CompletableFuture<T> future) {
        if (future.isDone()) {
            // Nothing to do.
            return;
        }

        boolean autoCancel = false;
        synchronized (this.futures) {
            Preconditions.checkNotNull(future, "future");
            if (this.cancellationRequested) {
                autoCancel = true;
            } else {
                this.futures.add(future);
            }
        }

        if (autoCancel) {
            // CancellationToken is already cancelled. Don't register anything, yet cancel the future we're given.
            future.cancel(true);
            return;
        }

        // Cleanup once the future is completed.
        future.whenComplete((r, ex) -> {
            synchronized (this.futures) {
                this.futures.remove(future);
            }
        });
    }
1235326
public static <T> @NonNull CompletableFuture<T> immediateFailedFuture(final @NonNull Throwable ex) {
    final CompletableFuture<T> future = new CompletableFuture<>();
    future.completeExceptionally(ex);
    return future;
  }
809813
public CompletableFuture<Void> compact() {
    ComposableFuture<Void> future = new ComposableFuture<>();
    threadContext.execute(() -> stateMachine.compact().whenComplete(future));
    return future;
  }
1174013
private <T> T complete(CompletableFuture<T> future, int acquirePermits) {
    AtomicBoolean needRelease = new AtomicBoolean(false);
    try {
      return future.thenApply(value -> {
        if (needRelease.get()) {
          if (acquirePermits > 0) {
            asyncSemaphore.release(acquirePermits);
          }
        }
        return value;
      }).get(timeout.toMillis(), TimeUnit.MILLISECONDS);
    } catch (InterruptedException | PrimitiveException.Interrupted e) {
      needRelease.set(acquirePermits > 0);
      Thread.currentThread().interrupt();
      throw new PrimitiveException.Interrupted();
    } catch (TimeoutException | PrimitiveException.Timeout e) {
      needRelease.set(acquirePermits > 0);
      throw new PrimitiveException.Timeout();
    } catch (ExecutionException e) {
      needRelease.set(acquirePermits > 0);
      Throwable cause = Throwables.getRootCause(e);
      if (cause instanceof PrimitiveException) {
        throw (PrimitiveException) cause;
      } else {
        throw new PrimitiveException(cause);
      }
    }
  }