/** * Returns a non-contextual instance. * * @param vertx * @return a new worker instance */ public static AsyncWorker from(Vertx vertx) { return new AsyncWorker(vertx); }
@Test public void testWorkerNonBlocking(TestContext context) throws InterruptedException, ExecutionException { BlockingFoo.reset(); Async async = context.async(); BlockingFoo foo = weld.select(BlockingFoo.class).get(); AsyncWorker.from(vertx).perform(foo::getMessageNonBlocking).thenAccept(m -> { context.assertEquals(BlockingFoo.class.getName(), m); async.complete(); }); } }
@Test public void testWorker(TestContext context) throws InterruptedException, ExecutionException { BlockingFoo.reset(); Async async = context.async(); BlockingFoo foo = weld.select(BlockingFoo.class).get(); AsyncWorker.from(vertx).performBlocking(foo::getMessage).thenAccept(m -> { context.assertEquals("ping", m); async.complete(); }); context.assertEquals(1, async.count()); BlockingFoo.complete("ping"); }
CompletionStage<String> hello() { return worker.performBlocking(foo::getMessage).thenApply(m -> "Hello " + m + "!"); }
CompletionStage<String> hello() { return alphaReference.thenCompose(alpha -> // At this point BlockingAlpha is ready // But getMessage() is also blocking worker.performBlocking(alpha::getMessage) // Finally modify the final message .thenApply(m -> "Hello " + m + "!")); }
/** * Returns a non-contextual instance. * * @param vertx * @return a new worker instance */ public static AsyncWorker from(Vertx vertx) { return new AsyncWorker(vertx); }