Skip to content
Merged
Show file tree
Hide file tree
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: 26 additions & 0 deletions vertx-core/src/main/java/io/vertx/core/Future.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@

package io.vertx.core;

import io.vertx.codegen.annotations.GenIgnore;
import io.vertx.core.impl.WorkerExecutor;
import io.vertx.core.internal.ContextInternal;
import io.vertx.core.impl.Utils;
import io.vertx.core.impl.future.CompositeFutureImpl;
import io.vertx.core.impl.future.FailedFuture;
import io.vertx.core.impl.future.SucceededFuture;

import java.time.Duration;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.*;
Expand Down Expand Up @@ -631,6 +633,17 @@ default Future<T> andThen(Completable<? super T> handler) {
*/
Future<T> timeout(long delay, TimeUnit unit);

/**
* Like {@link #timeout(long, TimeUnit)}.
*
* @param delay the delay
* @return the timeout future
*/
@GenIgnore(GenIgnore.PERMITTED_TYPE)
default Future<T> timeout(Duration delay) {
return timeout(delay.toMillis(), TimeUnit.MILLISECONDS);
}

/**
* Bridges this Vert.x future to a {@link CompletionStage} instance.
* <p>
Expand Down Expand Up @@ -746,6 +759,19 @@ default T await() {
return getOrFail();
}

/**
* Like {@link #await()} but with a timeout.
*
* @param timeout the timeout
* @return the result
* @throws TimeoutException when the timeout fires before the future completes
* @throws IllegalStateException when called from a vertx event-loop or worker thread
*/
@GenIgnore(GenIgnore.PERMITTED_TYPE)
default T await(Duration timeout) throws TimeoutException {
return await(timeout.toMillis(), TimeUnit.MILLISECONDS);
}

/**
* Like {@link #await()} but with a timeout.
*
Expand Down
12 changes: 12 additions & 0 deletions vertx-core/src/main/java/io/vertx/core/Vertx.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import io.vertx.core.spi.cluster.ClusterManager;
import io.vertx.core.transport.Transport;

import java.time.Duration;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -596,6 +597,17 @@ default Timer timer(long delay, TimeUnit unit) {
return ctx.timer(delay, unit);
}

/**
* Like {@link #timer(long, TimeUnit)}.
*
* @param delay the delay
* @return the timer object
*/
@GenIgnore(GenIgnore.PERMITTED_TYPE)
default Timer timer(Duration delay) {
return timer(delay.toMillis(), TimeUnit.MILLISECONDS);
}

/**
* Set a one-shot timer to fire after {@code delay} milliseconds, at which point {@code handler} will be called with
* the id of the timer.
Expand Down
Loading