Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Futurize MyVerticle start/stop example - backport to 4.x #5315

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions src/main/asciidoc/override/verticles.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class MyVerticle extends AbstractVerticle {

private HttpServer server;

@Override
public void start(Promise<Void> startPromise) {
server = vertx.createHttpServer().requestHandler(req -> {
req.response()
Expand All @@ -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)
.<Void>mapEmpty()
.onComplete(startPromise);
}
}
----
Expand All @@ -77,18 +74,11 @@ cleanup that takes some time.
----
public class MyVerticle extends AbstractVerticle {

public void start() {
// Do something
}

@Override
public void stop(Promise<Void> stopPromise) {
obj.doSomethingThatTakesTime(res -> {
if (res.succeeded()) {
stopPromise.complete();
} else {
stopPromise.fail();
}
});
doSomethingThatTakesTime()
.<Void>mapEmpty()
.onComplete(stopPromise);
}
}
----
Expand Down
Loading