io.vertx.core

## Interface AsyncResult<T>

- All Known Subinterfaces:
    BaseBridgeEvent, BridgeEvent, BridgeEvent, CompositeFuture, Future<T>

      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 Summary

    All Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `Throwable` | `cause()` A Throwable describing failure.
    `boolean` | `failed()` Did it fail?
    `default <U> AsyncResult<U>` | `map(java.util.function.Function<T,U> mapper)` Apply a `mapper` function on this async result.
    `default <V> AsyncResult<V>` | `map(V value)` Map the result of this async result to a specific `value`.
    `default <V> AsyncResult<V>` | `mapEmpty()` Map the result of this async result to `null`.
    `default AsyncResult<T>` | `otherwise(java.util.function.Function<Throwable,T> mapper)` Apply a `mapper` function on this async result.
    `default AsyncResult<T>` | `otherwise(T value)` Map the failure of this async result to a specific `value`.
    `default AsyncResult<T>` | `otherwiseEmpty()` Map the failure of this async result to `null`.
    `T` | `result()` The result of the operation.
    `boolean` | `succeeded()` Did it succeed?

- - ### 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<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

Copyright © 2019 Eclipse. All rights reserved.