当前位置: 首页>>代码示例>>Java>>正文


Java Context.executeBlocking方法代码示例

本文整理汇总了Java中io.vertx.core.Context.executeBlocking方法的典型用法代码示例。如果您正苦于以下问题:Java Context.executeBlocking方法的具体用法?Java Context.executeBlocking怎么用?Java Context.executeBlocking使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.vertx.core.Context的用法示例。


在下文中一共展示了Context.executeBlocking方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: supplyBlockingAsync

import io.vertx.core.Context; //导入方法依赖的package包/类
/**
 * Returns a new CompletableFuture that is asynchronously completed by a task
 * running in the worker thread pool of Vert.x
 * <p>
 * This method is different from
 * {@link CompletableFuture#supplyAsync(Supplier)} as it does not use a fork
 * join executor, but the worker thread pool.
 *
 * @param context  the context in which the supplier is executed.
 * @param supplier a function returning the value to be used to complete the returned
 *                 CompletableFuture
 * @param <T>      the function's return type
 * @return the new CompletableFuture
 */
public static <T> VertxCompletableFuture<T> supplyBlockingAsync(Context context, Supplier<T> supplier) {
  Objects.requireNonNull(supplier);
  VertxCompletableFuture<T> future = new VertxCompletableFuture<>(context);
  context.<T>executeBlocking(fut -> {
    try {
      fut.complete(supplier.get());
    } catch (Throwable e) {
      fut.fail(e);
    }
  }, ar -> {
    if (ar.failed()) {
      future.completeExceptionally(ar.cause());
    } else {
      future.complete(ar.result());
    }
  });
  return future;
}
 
开发者ID:jspare-projects,项目名称:vertx-jspare,代码行数:33,代码来源:VertxCompletableFuture.java

示例2: runBlockingAsync

import io.vertx.core.Context; //导入方法依赖的package包/类
/**
 * Returns a new CompletableFuture that is asynchronously completed by a action running in the worker thread pool of
 * Vert.x
 * <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;
}
 
开发者ID:cescoffier,项目名称:vertx-completable-future,代码行数:29,代码来源:VertxCompletableFuture.java

示例3: supplyBlockingAsync

import io.vertx.core.Context; //导入方法依赖的package包/类
/**
 * Returns a new CompletableFuture that is asynchronously completed by a task running in the worker thread pool of
 * Vert.x
 * <p>
 * This method is different from {@link CompletableFuture#supplyAsync(Supplier)} as it does not use a fork join
 * executor, but the worker thread pool.
 *
 * @param context  the context in which the supplier is executed.
 * @param supplier a function returning the value to be used to complete the returned CompletableFuture
 * @param <T>      the function's return type
 * @return the new CompletableFuture
 */
public static <T> VertxCompletableFuture<T> supplyBlockingAsync(Context context, Supplier<T> supplier) {
  Objects.requireNonNull(supplier);
  VertxCompletableFuture<T> future = new VertxCompletableFuture<>(context);
  context.<T>executeBlocking(
      fut -> {
        try {
          fut.complete(supplier.get());
        } catch (Throwable e) {
          fut.fail(e);
        }
      },
      ar -> {
        if (ar.failed()) {
          future.completeExceptionally(ar.cause());
        } else {
          future.complete(ar.result());
        }
      }
  );
  return future;
}
 
开发者ID:cescoffier,项目名称:vertx-completable-future,代码行数:34,代码来源:VertxCompletableFuture.java

示例4: runBlockingAsync

import io.vertx.core.Context; //导入方法依赖的package包/类
/**
 * Returns a new CompletableFuture that is asynchronously completed by a
 * action running in the worker thread pool of Vert.x
 * <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;
}
 
开发者ID:jspare-projects,项目名称:vertx-jspare,代码行数:27,代码来源:VertxCompletableFuture.java


注:本文中的io.vertx.core.Context.executeBlocking方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。