Added promise on VertxInternal to create them from the current context

This commit is contained in:
Julien Viet
2019-11-21 12:01:16 +01:00
parent 8fc6a5806c
commit a794a8ff69
2 changed files with 24 additions and 0 deletions

View File

@@ -352,6 +352,23 @@ public class VertxImpl implements VertxInternal, MetricsProvider {
return new TimeoutStreamImpl(delay, false);
}
@Override
public <T> PromiseInternal<T> promise() {
ContextInternal context = getOrCreateContext();
return context.promise();
}
@Override
public <T> PromiseInternal<T> promise(Handler<AsyncResult<T>> handler) {
if (handler instanceof PromiseInternal) {
return (PromiseInternal<T>) handler;
} else {
PromiseInternal<T> promise = promise();
promise.future().setHandler(handler);
return promise;
}
}
public void runOnContext(Handler<Void> task) {
ContextInternal context = getOrCreateContext();
context.runOnContext(task);

View File

@@ -39,6 +39,13 @@ import java.util.concurrent.TimeUnit;
*/
public interface VertxInternal extends Vertx {
/**
* @return a promise associated with the context returned by {@link #getOrCreateContext()}.
*/
<T> PromiseInternal<T> promise();
<T> PromiseInternal<T> promise(Handler<AsyncResult<T>> handler);
long maxEventLoopExecTime();
TimeUnit maxEventLoopExecTimeUnit();