Interface CommandResult

All Known Implementing Classes:
FutureCommandResult

public interface CommandResult
Interface describing the result from command handling.
Since:
0.6.0
Author:
Allard Buijze
  • Method Details

    • getResultMessage

      CompletableFuture<? extends Message> getResultMessage()
      Returns the result Message within a CompletableFuture of command handling.
      Returns:
      The result Message within a CompletableFuture of command handling.
    • resultAs

      default <R> CompletableFuture<R> resultAs(@Nonnull Class<R> type)
      Returns the result of command handling, cast to the given type, within a CompletableFuture.
      Type Parameters:
      R - The type of the command result.
      Parameters:
      type - The expected result type of command handling.
      Returns:
      The result of command handling, cast to the given type, within a CompletableFuture.
    • onSuccess

      default CommandResult onSuccess(@Nonnull Consumer<Message> successHandler)
      Attaches the given successHandler to this command result.

      The successHandler is invoked when command handling resolves successfully.

      Parameters:
      successHandler - A consumer of the command result Message, to be invoked upon successful command handling.
      Returns:
      This command result, invoking the given successHandler when command handling resolves successfully.
    • onSuccess

      default <R> CommandResult onSuccess(@Nonnull Class<R> resultType, @Nonnull BiConsumer<R,Message> successHandler)
      Attaches the given successHandler to this command result, expecting the given resultType.

      The successHandler is invoked when command handling resolves successfully.

      Type Parameters:
      R - The type of the command result.
      Parameters:
      resultType - The expected result type of command handling.
      successHandler - A bi-consumer of the command result Message, to be invoked upon successful command handling.
      Returns:
      This command result, invoking the given successHandler when command handling resolves successfully.
    • onSuccess

      default <R> CommandResult onSuccess(@Nonnull Class<R> resultType, @Nonnull Consumer<R> successHandler)
      Attaches the given successHandler to this command result, expecting the given resultType.

      The successHandler is invoked when command handling resolves successfully.

      Type Parameters:
      R - The type of the command result.
      Parameters:
      resultType - The expected result type of command handling.
      successHandler - A consumer of the command result Message, to be invoked upon successful command handling.
      Returns:
      This command result, invoking the given successHandler when command handling resolves successfully.
    • onError

      default CommandResult onError(@Nonnull Consumer<Throwable> errorHandler)
      Attaches the given errorHandler to this command result.

      The errorHandler is invoked when command handling fails.

      Parameters:
      errorHandler - A consumer of the Throwable that may follow when command handling fails.
      Returns:
      This command result, invoking the given errorHandler when command handling resolves with an error.
    • wait

      default <R> R wait(@Nonnull Class<R> resultType)
      Waits for the result of command handling, cast to the given type.
      Type Parameters:
      R - The type of the command result.
      Parameters:
      resultType - The expected result type of command handling.
      Returns:
      The result of command handling, cast to the given type.
      Throws:
      CommandExecutionException - When a checked exception occurs while waiting for the result.