Interface Callback

All Known Implementing Classes:
Callback.Completable

public interface Callback

A callback object that handles success/failure events of asynchronous operations.

NOTE: This interface is almost identical to org.eclipse.jetty.util.Callback, which however cannot be used in the Jetty WebSocket APIs for web application classloading reasons.

  • Field Details

    • NOOP

      static final Callback NOOP

      Empty implementation.

  • Method Details

    • from

      static Callback from(Runnable success, Consumer<Throwable> failure)

      Creates a callback from the given success and failure lambdas.

      Parameters:
      success - the success action to invoke when the callback succeeds
      failure - the failure consumer to invoke when the callback fails
      Returns:
      a new callback
    • from

      static Callback from(Callback callback, Runnable completed)
      Creates a nested callback that runs completed after completing the nested callback.
      Parameters:
      callback - The nested callback
      completed - The completion to run after the nested callback is completed
      Returns:
      a new callback.
    • succeed

      default void succeed()

      Method to invoke to succeed the callback.

      See Also:
    • fail

      default void fail(Throwable x)

      Method to invoke to fail the callback.

      Parameters:
      x - the failure
    • asBiConsumer

      default BiConsumer<? super Void,? super Throwable> asBiConsumer()

      Converts this callback into a BiConsumer that can be passed to CompletableFuture.whenComplete(BiConsumer).

      When the BiConsumer is accepted, this callback is completed.

      Returns:
      a BiConsumer that completes this callback
      See Also: