Class FlatMapErrorRestAction<T>
java.lang.Object
net.dv8tion.jda.internal.requests.restaction.operator.RestActionOperator<T,T>
net.dv8tion.jda.internal.requests.restaction.operator.FlatMapErrorRestAction<T>
- All Implemented Interfaces:
RestAction<T>
-
Constructor Summary
ConstructorsConstructorDescriptionFlatMapErrorRestAction
(RestAction<T> action, Predicate<? super Throwable> check, Function<? super Throwable, ? extends RestAction<? extends T>> map) -
Method Summary
Modifier and TypeMethodDescriptioncomplete
(boolean shouldQueue) Blocks the current Thread and awaits the completion of anRestAction.submit()
request.void
Submits a Request for execution.submit
(boolean shouldQueue) Submits a Request for execution and provides aCompletableFuture
representing its completion task.Methods inherited from class net.dv8tion.jda.internal.requests.restaction.operator.RestActionOperator
deadline, getCheck, getJDA, setCheck
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.dv8tion.jda.api.requests.RestAction
addCheck, and, and, complete, completeAfter, delay, delay, delay, delay, flatMap, flatMap, map, mapToResult, onErrorFlatMap, onErrorFlatMap, onErrorMap, onErrorMap, onSuccess, queue, queue, queueAfter, queueAfter, queueAfter, queueAfter, queueAfter, queueAfter, submit, submitAfter, submitAfter, timeout, zip
-
Constructor Details
-
FlatMapErrorRestAction
public FlatMapErrorRestAction(RestAction<T> action, Predicate<? super Throwable> check, Function<? super Throwable, ? extends RestAction<? extends T>> map)
-
-
Method Details
-
queue
public void queue(@Nullable Consumer<? super T> success, @Nullable Consumer<? super Throwable> failure) Description copied from interface:RestAction
Submits a Request for execution.This method is asynchronous
Example
public static void sendPrivateMessage(JDA jda, String userId, String content) { // Retrieve the user by their id RestAction<User> action = jda.retrieveUserById(userId); action.queue( // Handle success if the user exists (user) -> user.openPrivateChannel().queue( (channel) -> channel.sendMessage(content).queue()), // Handle failure if the user does not exist (or another issue appeared) (error) -> error.printStackTrace() ); // Alternatively use submit() to remove nested callbacks }
- Parameters:
success
- The success callback that will be called at a convenient time for the API. (can be null to use default)failure
- The failure callback that will be called if the Request encounters an exception at its execution point. (can be null to use default)- See Also:
-
complete
Description copied from interface:RestAction
Blocks the current Thread and awaits the completion of anRestAction.submit()
request.
Used for synchronous logic.- Parameters:
shouldQueue
- Whether this should automatically handle rate limitations (default true)- Returns:
- The response value
- Throws:
RateLimitedException
- If we were rate limited and theshouldQueue
is false. UseRestAction.complete()
to avoid this Exception.
-
submit
Description copied from interface:RestAction
Submits a Request for execution and provides aCompletableFuture
representing its completion task.
Cancelling the returned Future will result in the cancellation of the Request!- Parameters:
shouldQueue
- Whether the Request should automatically handle rate limitations. (default true)- Returns:
- Never-null
CompletableFuture
task representing the completion promise
-