Package io.vertx.core

Interface AsyncResult<T>

  • All Known Subinterfaces:
    CompositeFuture, Future<T>, Timer

    public interface AsyncResult<T>
    Encapsulates the result of an asynchronous operation.

    Many operations in Vert.x APIs provide results back by passing an instance of this in a Handler.

    The result can either have failed or succeeded.

    If it failed then the cause of the failure is available with cause().

    If it succeeded then the actual result is available with result()

    Author:
    Tim Fox
    • Method Detail

      • result

        T result()
        The result of the operation. This will be null if the operation failed.
        Returns:
        the result or null if the operation failed.
      • cause

        Throwable cause()
        A Throwable describing failure. This will be null if the operation succeeded.
        Returns:
        the cause or null if the operation succeeded.
      • succeeded

        boolean succeeded()
        Did it succeed?
        Returns:
        true if it succeded or false otherwise
      • failed

        boolean failed()
        Did it fail?
        Returns:
        true if it failed or false otherwise
      • map

        default <U> AsyncResult<U> map​(java.util.function.Function<? super T,​U> mapper)
        Apply a mapper function on this async result.

        The mapper is called with the completed value and this mapper returns a value. This value will complete the result returned by this method call.

        When this async result is failed, the failure will be propagated to the returned async result and the mapper will not be called.

        Parameters:
        mapper - the mapper function
        Returns:
        the mapped async result
      • map

        default <V> AsyncResult<V> map​(V value)
        Map the result of this async result to a specific value.

        When this async result succeeds, this value 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.

        Parameters:
        value - the value that eventually completes the mapped async result
        Returns:
        the mapped async result
      • mapEmpty

        default <V> AsyncResult<V> mapEmpty()
        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.

        Returns:
        the mapped async result
      • otherwise

        default AsyncResult<T> otherwise​(java.util.function.Function<Throwable,​T> mapper)
        Apply a mapper function on this async result.

        The mapper is called with the failure and this mapper returns a value. This value will complete the result returned by this method call.

        When this async result is succeeded, the value will be propagated to the returned async result and the mapper will not be called.

        Parameters:
        mapper - the mapper function
        Returns:
        the mapped async result
      • otherwise

        default AsyncResult<T> otherwise​(T value)
        Map the failure of this async result to a specific value.

        When this async result fails, this value will succeeed the async result returned by this method call.

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

        Parameters:
        value - the value that eventually completes the mapped async result
        Returns:
        the mapped async result
      • otherwiseEmpty

        default AsyncResult<T> otherwiseEmpty()
        Map the failure of this async result to null.

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

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

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

        Returns:
        the mapped async result