Example usage for io.netty.util.concurrent DefaultPromise setFailure

List of usage examples for io.netty.util.concurrent DefaultPromise setFailure

Introduction

In this page you can find the example usage for io.netty.util.concurrent DefaultPromise setFailure.

Prototype

@Override
    public Promise<V> setFailure(Throwable cause) 

Source Link

Usage

From source file:com.lambdaworks.redis.resource.Futures.java

License:Apache License

/**
 * Create a promise that emits a {@code Boolean} value on completion of the {@code future}
 * /* ww  w  . j  a v a  2s.co  m*/
 * @param future the future.
 * @return Promise emitting a {@code Boolean} value. {@literal true} if the {@code future} completed successfully, otherwise
 *         the cause wil be transported.
 */
static Promise<Boolean> toBooleanPromise(Future<?> future) {
    final DefaultPromise<Boolean> result = new DefaultPromise<>(GlobalEventExecutor.INSTANCE);

    future.addListener(new GenericFutureListener<Future<Object>>() {
        @Override
        public void operationComplete(Future<Object> future) throws Exception {

            if (future.isSuccess()) {
                result.setSuccess(true);
            } else {
                result.setFailure(future.cause());
            }
        }
    });
    return result;
}

From source file:io.lettuce.core.resource.Futures.java

License:Apache License

/**
 * Create a promise that emits a {@code Boolean} value on completion of the {@code future}
 *
 * @param future the future.//from   www.  jav  a 2 s .  c o m
 * @return Promise emitting a {@code Boolean} value. {@literal true} if the {@code future} completed successfully, otherwise
 *         the cause wil be transported.
 */
static Promise<Boolean> toBooleanPromise(Future<?> future) {

    DefaultPromise<Boolean> result = new DefaultPromise<>(GlobalEventExecutor.INSTANCE);

    if (future.isDone() || future.isCancelled()) {
        if (future.isSuccess()) {
            result.setSuccess(true);
        } else {
            result.setFailure(future.cause());
        }
        return result;
    }

    future.addListener((GenericFutureListener<Future<Object>>) f -> {

        if (f.isSuccess()) {
            result.setSuccess(true);
        } else {
            result.setFailure(f.cause());
        }
    });
    return result;
}