I'm trying to get a completable future out of a vertx-web-client call:
WebClient.create(vertx)
.postAbs("http://example.com/post-path")
.sendJsonObject(request, res -> {...});
The solution that was obvious to me was to create a pending VertxCompletableFuture and call .toFuture() on it (since the Vert.x's Future implements Handler):
var responseFuture = new VertxCompletableFuture<HttpResponse<Buffer>>(vertx);
WebClient.create(vertx)
.postAbs("http://example.com/post-path")
.sendJsonObject(request, responseFuture.toFuture());
var response = await(responseFuture);
I'm trying to get a completable future out of a
vertx-web-client
call:The solution that was obvious to me was to create a pending
VertxCompletableFuture
and call.toFuture()
on it (since the Vert.x'sFuture
implementsHandler
):However,
responseFuture
will never be completed because.toFuture()
hooks up the callbacks in theVertxCompletableFuture
->Future
direction only: https://github.com/cescoffier/vertx-completable-future/blob/master/src/main/java/me/escoffier/vertx/completablefuture/VertxCompletableFuture.java#L546The fix is to create a
Future
first and useVertxCompletableFuture.from()
but it's an extra step: