Skip to content

Commit

Permalink
More docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Nov 15, 2024
1 parent 5a8ea04 commit 13f7b78
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions vertx-core/src/main/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,11 @@ To cancel a periodic timer, call {@link io.vertx.core.Vertx#cancelTimer} specify

{@link io.vertx.core.Timer} combines one-shot timer and {@link {@link io.vertx.core.Future} in a single API.

[source,$lang]
----
{@link examples.CoreExamples#timerExample}
----

The future succeeds when the timer fires, conversely {@link io.vertx.core.Timer#cancel() cancelling} the timer fails the future.

==== Automatic clean-up in verticles
Expand Down
11 changes: 9 additions & 2 deletions vertx-core/src/main/java/examples/CoreExamples.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,16 @@ public void example17(Vertx vertx, long timerID) {

public void timerExample(Vertx vertx) {
// Create a timer
Timer timer = vertx.timer(10, TimeUnit.SECONDS);

Future<String> timer = vertx
.timer(10, TimeUnit.SECONDS)
.map(v -> "Success");

timer.onSuccess(value -> {
System.out.println("Timer fired: " + value);
});
timer.onFailure(cause -> {
System.out.println("Timer cancelled: " + cause.getMessage());
});
}

public void example18(String className, Exception exception) {
Expand Down

0 comments on commit 13f7b78

Please sign in to comment.