All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.edgar615.util.vertx.base.Futures Maven / Gradle / Ivy

The newest version!
package com.github.edgar615.util.vertx.base;

import io.vertx.core.Future;

import java.util.concurrent.CompletableFuture;

/**
 * Created by Edgar on 2017/9/12.
 *
 * @author Edgar  Date 2017/9/12
 */
public class Futures {

  public static  CompletableFuture toCompletableFuture(Future future) {
    CompletableFuture completableFuture = new CompletableFuture<>();
    future.setHandler(ar -> {
      if (ar.succeeded()) {
        completableFuture.complete(ar.result());
      } else {
        completableFuture.completeExceptionally(ar.cause());
      }
    });
    return completableFuture;
  }

  public static  Future toFuture(CompletableFuture completableFuture) {
    Future future = Future.future();
    completableFuture.thenAccept(r -> future.complete(r))
            .exceptionally(t -> {
              future.fail(t);
              return null;
            });
    return future;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy