List of usage examples for io.vertx.core Context executeBlocking
<T> Future<@Nullable T> executeBlocking(Handler<Promise<T>> blockingCodeHandler, boolean ordered);
From source file:io.gravitee.fetcher.http.vertx.VertxCompletableFuture.java
License:Apache License
/** * Returns a new CompletableFuture that is asynchronously completed by a action running in the worker thread pool of * Vert.x/*from w ww . j a v a 2s.c o m*/ * <p> * This method is different from {@link CompletableFuture#runAsync(Runnable)} as it does not use a fork join * executor, but the worker thread pool. * * @param context the Vert.x context * @param runnable the action, when its execution completes, it completes the returned CompletableFuture. If the * execution throws an exception, the returned CompletableFuture is completed exceptionally. * @return the new CompletableFuture */ public static VertxCompletableFuture<Void> runBlockingAsync(Context context, Runnable runnable) { Objects.requireNonNull(runnable); VertxCompletableFuture<Void> future = new VertxCompletableFuture<>(Objects.requireNonNull(context)); context.executeBlocking(fut -> { try { runnable.run(); future.complete(null); } catch (Throwable e) { future.completeExceptionally(e); } }, null); return future; }