From d3a269ba5a644bd811d6abca0533b0a46199a041 Mon Sep 17 00:00:00 2001 From: julianladisch Date: Thu, 4 May 2023 15:24:18 +0200 Subject: [PATCH] Futurize MyVerticle start/stop example - backport to 4.x (cherry picked from commit 31a03d7ae8075d29519272214989e111ef4e374e) Signed-off-by: Julian Ladisch Co-authored-by: Thomas Segismont --- src/main/asciidoc/override/verticles.adoc | 26 +++++++---------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/main/asciidoc/override/verticles.adoc b/src/main/asciidoc/override/verticles.adoc index 3ca03a563b5..53faeb1ca51 100644 --- a/src/main/asciidoc/override/verticles.adoc +++ b/src/main/asciidoc/override/verticles.adoc @@ -52,6 +52,7 @@ public class MyVerticle extends AbstractVerticle { private HttpServer server; + @Override public void start(Promise startPromise) { server = vertx.createHttpServer().requestHandler(req -> { req.response() @@ -60,13 +61,9 @@ public class MyVerticle extends AbstractVerticle { }); // Now bind the server: - server.listen(8080, res -> { - if (res.succeeded()) { - startPromise.complete(); - } else { - startPromise.fail(res.cause()); - } - }); + server.listen(8080) + .mapEmpty() + .onComplete(startPromise); } } ---- @@ -77,18 +74,11 @@ cleanup that takes some time. ---- public class MyVerticle extends AbstractVerticle { - public void start() { - // Do something - } - + @Override public void stop(Promise stopPromise) { - obj.doSomethingThatTakesTime(res -> { - if (res.succeeded()) { - stopPromise.complete(); - } else { - stopPromise.fail(); - } - }); + doSomethingThatTakesTime() + .mapEmpty() + .onComplete(stopPromise); } } ----