Not sure if this is necessarily true as there's a factory method in CompletableFuture that allows CF's to run in the context of non-default ForkJoinPool.
To be honest, I still do not understand the implications of having CompletableFuture execute through an Executor different from the one used by Vert.X itself. If I call join() on the CF running on a different pool, then that's going to make the event loop wait, but what I'm planning to do is return a CompletionStage in my API and so client code won't be able to do that unless then explicitly wrap that in another CF. If I understand correctly, once the CF forked from the main thread (event loop in the context of Vert.X) the callback is run in the context of the calling thread, which is the event loop. So if I have the following code:
CompletionStage<List<Books>> findBooks = bookService.findAllAsync();
findBooks.thenApply(books -> {
//process books here as booksJson
vertxEvent.reply(booksJson);
});
the
thenApply callback is run in the context of the Vert.X's event loop, isn't it? If that's the case, then wouldn't it be good since, regardless of where the process of finding books occur, when the control goes back to the Vert.X event loop, it's only going to spend the time converting the result to JSON and send it back to the Vert.X component that originally started the operation?