本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}