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 Summary
Modifier and TypeMethodDescriptionCompletableFuture<? extends Message> Returns the resultMessagewithin aCompletableFutureof command handling.default CommandResultAttaches the givenerrorHandlertothiscommand result.default <R> CommandResultonSuccess(Class<R> resultType, BiConsumer<R, Message> successHandler) Attaches the givensuccessHandlertothiscommand result, expecting the givenresultType.default <R> CommandResultAttaches the givensuccessHandlertothiscommand result, expecting the givenresultType.default CommandResultAttaches the givensuccessHandlertothiscommand result.default <R> CompletableFuture<R> Returns the result of command handling, cast to the giventype, within aCompletableFuture.default <R> RWaits for the result of command handling, cast to the giventype.
-
Method Details
-
getResultMessage
CompletableFuture<? extends Message> getResultMessage()Returns the resultMessagewithin aCompletableFutureof command handling.- Returns:
- The result
Messagewithin aCompletableFutureof command handling.
-
resultAs
Returns the result of command handling, cast to the giventype, within aCompletableFuture.- 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 aCompletableFuture.
-
onSuccess
Attaches the givensuccessHandlertothiscommand result.The
successHandleris invoked when command handling resolves successfully.- Parameters:
successHandler- A consumer of the command resultMessage, to be invoked upon successful command handling.- Returns:
- This command result, invoking the given
successHandlerwhen command handling resolves successfully.
-
onSuccess
default <R> CommandResult onSuccess(@Nonnull Class<R> resultType, @Nonnull BiConsumer<R, Message> successHandler) Attaches the givensuccessHandlertothiscommand result, expecting the givenresultType.The
successHandleris 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 resultMessage, to be invoked upon successful command handling.- Returns:
- This command result, invoking the given
successHandlerwhen command handling resolves successfully.
-
onSuccess
default <R> CommandResult onSuccess(@Nonnull Class<R> resultType, @Nonnull Consumer<R> successHandler) Attaches the givensuccessHandlertothiscommand result, expecting the givenresultType.The
successHandleris 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 resultMessage, to be invoked upon successful command handling.- Returns:
- This command result, invoking the given
successHandlerwhen command handling resolves successfully.
-
onError
Attaches the givenerrorHandlertothiscommand result.The
errorHandleris invoked when command handling fails.- Parameters:
errorHandler- A consumer of theThrowablethat may follow when command handling fails.- Returns:
- This command result, invoking the given
errorHandlerwhen command handling resolves with an error.
-
wait
Waits for the result of command handling, cast to the giventype.- 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.
-