Example usage for io.vertx.core Future otherwiseEmpty

List of usage examples for io.vertx.core Future otherwiseEmpty

Introduction

In this page you can find the example usage for io.vertx.core Future otherwiseEmpty.

Prototype

default Future<T> otherwiseEmpty() 

Source Link

Document

Map the failure of a future to null .

This is a convenience for future.otherwise((T) null) .

When this future fails, the null value will complete the future returned by this method call.

When this future succeeds, the result will be propagated to the returned future.

Usage

From source file:org.eclipse.hono.tests.registry.DeviceRegistryAmqpTestSupport.java

License:Open Source License

/**
 * Closes the connection of the provided client to the device registry service.
 * <p>//from  w w  w.j a  v  a2s  .  c om
 * Any senders or consumers opened by this client will be implicitly closed as well. Any subsequent attempts to
 * connect this client again will fail.
 *
 * @param vertx The Vert.x instance on which the client is executed on.
 * @param ctx The test context that the tests are executed on.
 * @param client The client to shutdown.
 * @throws NullPointerException if any of the parameters is {@code null}.
 */
protected static void shutdownDeviceRegistryClient(final TestContext ctx, final Vertx vertx,
        final HonoClient client) {

    final Future<Void> clientTracker = Future.future();
    if (client != null) {
        client.shutdown(clientTracker.completer());
    } else {
        clientTracker.complete();
    }
    clientTracker.otherwiseEmpty().compose(s -> {
        final Future<Void> vertxTracker = Future.future();
        vertx.close(vertxTracker.completer());
        return vertxTracker;
    }).setHandler(ctx.asyncAssertSuccess());
}