Converts  {@link com.google.api.core.ApiFuture} to {@link java.util.concurrent.CompletableFuture}.
547339
public static <T> CompletableFuture<T> toCompletableFuture(ApiFuture<T> apiFuture) {
        return Java8FutureUtils.createCompletableFuture(ApiFutureUtils.createValueSourceFuture(apiFuture));
    }
699100
public static <T> CompletableFuture<T> toCompletableFuture(ListenableFuture<T> listenableFuture) {
        return Java8FutureUtils.createCompletableFuture(SpringFutureUtils.createValueSourceFuture(listenableFuture));
    }
118217
public static <T> Future<T> ofResult(final T result) {
        return Future.of(CompletableFuture.completedFuture(result));
    }
153374
@SuppressWarnings({ "unchecked", "rawtypes" })
    public static CompletableFuture<Void> allOf(Collection<? extends CompletableFuture<?>> futures) {

        LettuceAssert.notNull(futures, "Futures must not be null");

        return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
    }
34500
public VertxCompletableFuture<T> withContext(Context context) {
    VertxCompletableFuture<T> future = new VertxCompletableFuture<>(Objects.requireNonNull(context));
    whenComplete((res, err) -> {
      if (err != null) {
        future.completeExceptionally(err);
      } else {
        future.complete(res);
      }
    });
    return future;
  }
605257
public CompletableFuture<Void> close() {
    if (state.getState() == Session.State.EXPIRED)
      return CompletableFuture.completedFuture(null);

    CompletableFuture<Void> future = new CompletableFuture<>();
    context.executor().execute(() -> {
      if (keepAlive != null) {
        keepAlive.cancel();
        keepAlive = null;
      }
      unregister(future);
    });
    return future;
  }
435950
public static <V> FutureCombiner<V> whenAllComplete(
      Iterable<? extends ListenableFuture<? extends V>> futures) {
    return new FutureCombiner<V>(false, ImmutableList.copyOf(futures));
  }
1294135
public static <T> CompletableFuture<T> failed(Throwable throwable) {

        LettuceAssert.notNull(throwable, "Throwable must not be null");

        CompletableFuture<T> future = new CompletableFuture<>();
        future.completeExceptionally(throwable);

        return future;
    }
1136851
@Override
    public CompletableFutureT<W,T> peek(final Consumer<? super T> peek) {
        return of(run.peek(future -> future.thenApply(a -> {
            peek.accept(a);
            return a;
        })));
    }
1148922
public static <T> @NonNull CompletableFuture<Optional<T>> emptyOptionalFuture() {
    return CompletableFuture.completedFuture(Optional.empty());
  }
758977
public <U> FutureStream<U> from(final CompletableFuture<U> cf) {

        return this.constructFutures(Stream.of(cf));

    }
678182
protected Object interceptCompletableFuture(MethodInvocationContext<Object, Object> context, ReturnType<?> returnTypeObject, Class returnType) {
        CacheOperation cacheOperation = new CacheOperation(context, returnType);
        AnnotationValue<Cacheable> cacheable = cacheOperation.cacheable;
        CompletableFuture<Object> returnFuture;
        if (cacheable != null) {
            AsyncCache<?> asyncCache = cacheManager.getCache(cacheOperation.cacheableCacheName).async();
            CacheKeyGenerator keyGenerator = resolveKeyGenerator(cacheOperation.defaultKeyGenerator, cacheable);
            Object[] params = resolveParams(context, cacheable.get(MEMBER_PARAMETERS, String[].class, StringUtils.EMPTY_STRING_ARRAY));
            Object key = keyGenerator.generateKey(context, params);
            CompletableFuture<Object> thisFuture = new CompletableFuture<>();
            Argument<?> firstTypeVariable = returnTypeObject.getFirstTypeVariable().orElse(Argument.of(Object.class));
            asyncCache.get(key, firstTypeVariable).whenComplete((BiConsumer<Optional<?>, Throwable>) (o, throwable) -> {
                if (throwable == null && o.isPresent()) {
                    // cache hit, return result
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Value found in cache [" + asyncCache.getName() + "] for invocation: " + context);
                    }
                    thisFuture.complete(o.get());
                } else {
                    // cache miss proceed with original future
                    try {
                        if (throwable != null) {
                            if (errorHandler.handleLoadError(asyncCache, key, asRuntimeException(throwable))) {
                                thisFuture.completeExceptionally(throwable);
                                return;
                            }
                        }
                        CompletableFuture<?> completableFuture = (CompletableFuture) context.proceed();
                        if (completableFuture == null) {
                            thisFuture.complete(null);
                        } else {
                            completableFuture.whenComplete((BiConsumer<Object, Throwable>) (o1, t2) -> {
                                if (t2 != null) {
                                    thisFuture.completeExceptionally(t2);
                                } else {
                                    // new cacheable result, cache it
                                    asyncCache.put(key, o1).whenComplete((aBoolean, throwable1) -> {
                                        if (throwable1 == null) {
                                            thisFuture.complete(o1);
                                        } else {
                                            thisFuture.completeExceptionally(throwable1);
                                        }
                                    });

                                }
                            });
                        }
                    } catch (RuntimeException e) {
                        thisFuture.completeExceptionally(e);
                    }
                }
            });
            returnFuture = thisFuture;
        } else {
            returnFuture = (CompletableFuture<Object>) context.proceed();
        }
        if (cacheOperation.hasWriteOperations()) {
            returnFuture = processFuturePutOperations(context, cacheOperation, returnFuture);
        }
        return returnFuture;
    }
485933
static CompletableFuture<Void> andTree(CompletableFuture<?>[] cfs, int lo, int hi) {
    CompletableFuture<Void> d = new CompletableFuture<Void>();
    if (lo > hi) // empty
      d.result = NIL;
    else {
      CompletableFuture<?> a, b;
      Object r, s, z;
      Throwable x;
      int mid = (lo + hi) >>> 1;
      if ((a = (lo == mid ? cfs[lo] : andTree(cfs, lo, mid))) == null
          || (b = (lo == hi ? a : (hi == mid + 1) ? cfs[hi] : andTree(cfs, mid + 1, hi))) == null)
        throw new NullPointerException();
      if ((r = a.result) == null || (s = b.result) == null)
        a.bipush(b, new BiRelay(d, a, b));
      else if ((r instanceof AltResult && (x = ((AltResult) (z = r)).ex) != null)
          || (s instanceof AltResult && (x = ((AltResult) (z = s)).ex) != null))
        d.result = encodeThrowable(x, z);
      else
        d.result = NIL;
    }
    return d;
  }
1348972
@Override
    public CompletableFuture<T> getNext() {
        // Verify no other call to getNext() is currently executing.
        return getNextBucket()
                .thenCompose(bucket -> {
                    if (bucket == null) {
                        // We are done.
                        return CompletableFuture.completedFuture(null);
                    } else {
                        // Convert the TableBucket into the desired result.
                        return this.resultConverter.apply(bucket);
                    }
                });
    }
590050
public static <T> com.google.common.util.concurrent.ListenableFuture<T> toGuavaListenableFuture(ListenableFuture<T> springListenableFuture) {
            return GuavaFutureUtils.createListenableFuture(SpringFutureUtils.createValueSourceFuture(springListenableFuture));
    }
471764
public CompletableFuture<Void> close() {
    CompletableFuture<Void> future = new CompletableFuture<>();
    threadContext.execute(() -> {
      try {
        clusterMembershipService.removeListener(membershipEventListener);
        primaryElection.removeListener(primaryElectionListener);
        role.close();
      } finally {
        future.complete(null);
      }
    });
    return future.thenRunAsync(() -> threadContext.close());
  }
1072521
public final static <T> CompletableFuture<List<T>> streamToCompletableFuture(final Stream<T> stream) {
        return CompletableFuture.completedFuture(stream.collect(Collectors.toList()));

    }