Returns the result of the first {@link RedisFuture} and guarantee that all futures are finished.

@param executions mapping of a key to the future
@param <T> result type
@return future returning the first result.
329474
protected static <T> RedisFuture<T> firstOfAsync(Map<?, ? extends CompletionStage<T>> executions) {

        return new PipelinedRedisFuture<>(executions, objectPipelinedRedisFuture -> {
            // make sure, that all futures are executed before returning the result.
                for (CompletionStage<T> future : executions.values()) {
                    execute(() -> future.toCompletableFuture().get());
                }
                for (CompletionStage<T> future : executions.values()) {
                    return execute(() -> future.toCompletableFuture().get());
                }
                return null;
            });
    }
493520
public static ExecutionResult failure(Throwable failure) {
    return new ExecutionResult(null, failure, false, 0, true, false, false);
  }
994848
@Override
  public Collection<FastFuture<T>> getResults() {
    active.stream()
      .forEach(cf -> safeJoin.apply(cf));
    active.clear();
    return new ArrayList<>();
  }
118217
public static <T> Future<T> ofResult(final T result) {
        return Future.of(CompletableFuture.completedFuture(result));
    }
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;
  }
134869
static ContinuableFuture<Void> executeWithThreadPool(final Try.Runnable<? extends Exception> action) {
        return execute(new FutureTask<Void>(FN.toCallable(action)), TP_EXECUTOR);
    }
662397
@Override
    public IPromise<T> then(Runnable result) {
        return then( (r,e) -> result.run() );
    }
79839
private CompletableFuture<T> orderedFuture() {
    if (!complete) {
      synchronized (orderedFutures) {
        if (!complete) {
          CompletableFuture<T> future = new CompletableFuture<>();
          orderedFutures.add(future);
          return future;
        }
      }
    }

    // Completed
    if (error == null) {
      return CompletableFuture.completedFuture(result);
    } else {
      return Futures.exceptionalFuture(error);
    }
  }
143004
public static <T> Future<T> execute(Callable<T> callable) throws RejectedExecutionException {
        return getValidExecutor().submit(wrapCallable(callable, MsgIdHolder.get()));
    }
100327
public void completeFuture(long entryIndex, Object response) {
        SimpleCompletableFuture f = futures.remove(entryIndex);
        if (f != null) {
            f.setResult(response);
        }
    }
708802
@Override
    public Future<M> getDataFuture() {
        try {
            return FutureProcessor.completedFuture(getData());
        } catch (NotAvailableException ex) {
            CompletableFuture future = new CompletableFuture();
            future.completeExceptionally(ex);
            return future;
        }
    }
924320
public static DispatcherException extractDispatcherException(final StepExecutionResult result) {
        Optional<NodeDispatchStepExecutorExceptionResult>
            extracted =
            extractNodeDispatchStepExecutorExceptionResult(result);
        if (!extracted.isPresent()) {
            throw new IllegalArgumentException("Cannot extract result: unexpected type: " + result);
        }
        return extracted.get().getDispatcherException();
    }
1185108
public CompletableFuture<byte[]> invoke(PrimitiveOperation operation) {
    CompletableFuture<byte[]> future = new CompletableFuture<>();
    switch (operation.id().type()) {
      case COMMAND:
        context.execute(() -> invokeCommand(operation, future));
        break;
      case QUERY:
        context.execute(() -> invokeQuery(operation, future));
        break;
      default:
        throw new IllegalArgumentException("Unknown operation type " + operation.id().type());
    }
    return future;
  }
1218755
@Override
  public boolean isFuture()
  {
    ResultChain<T> result = _result;

    return result.isFuture() && method().isDirect();
  }
1050545
protected static RedisFuture<Long> aggregateAsync(Map<?, ? extends CompletionStage<Long>> executions) {

        return new PipelinedRedisFuture<>(executions, objectPipelinedRedisFuture -> {
            AtomicLong result = new AtomicLong();
            for (CompletionStage<Long> future : executions.values()) {
                Long value = execute(() -> future.toCompletableFuture().get());
                if (value != null) {
                    result.getAndAdd(value);
                }
            }

            return result.get();
        });
    }
967371
@Beta
  public Future<HttpResponse> executeAsync() {
    return executeAsync(
        Executors.newFixedThreadPool(1, new ThreadFactoryBuilder().setDaemon(true).build()));
  }
1052458
@NotNull
	@SafeVarargs
	public static <T> Promise<T> firstSuccessful(AsyncSupplier<? extends T>... promises) {
		return first(isResult(), promises);
	}