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 + "!")); }
@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"); }