Example usage for io.vertx.core AsyncResult mapEmpty

List of usage examples for io.vertx.core AsyncResult mapEmpty

Introduction

In this page you can find the example usage for io.vertx.core AsyncResult mapEmpty.

Prototype

default <V> AsyncResult<V> mapEmpty() 

Source Link

Document

Map the result of this async result to null .

This is a convenience for asyncResult.map((T) null) or asyncResult.map((Void) null) .

When this async result succeeds, null will succeeed the async result returned by this method call.

When this async result fails, the failure will be propagated to the returned async result.

Usage

From source file:io.reactiverse.pgclient.impl.pubsub.PgSubscriberImpl.java

License:Apache License

private synchronized void handleConnectResult(Handler<AsyncResult<Void>> completionHandler,
        AsyncResult<PgConnection> ar1) {
    connecting = false;//from  ww w .  j av a  2 s  .  com
    if (ar1.succeeded()) {
        conn = ar1.result();
        conn.notificationHandler(PgSubscriberImpl.this::handleNotification);
        conn.closeHandler(PgSubscriberImpl.this::handleClose);
        if (channels.size() > 0) {
            List<Handler<Void>> handlers = channels.values().stream().flatMap(channel -> channel.subs.stream())
                    .map(sub -> sub.subscribeHandler).filter(Objects::nonNull).collect(Collectors.toList());
            String sql = channels.values().stream().map(channel -> {
                channel.subscribed = true;
                return channel.quotedName;
            }).collect(Collectors.joining(";LISTEN ", "LISTEN ", ""));
            conn.query(sql, ar2 -> {
                if (ar2.failed()) {
                    log.error("Cannot LISTEN to channels", ar2.cause());
                    conn.close();
                } else {
                    handlers.forEach(vertx::runOnContext);
                }
                completionHandler.handle(ar2.mapEmpty());
            });
            return;
        }
    }
    completionHandler.handle(ar1.mapEmpty());
}