Class MapRestAction<I,O>

java.lang.Object
net.dv8tion.jda.internal.requests.restaction.operator.RestActionOperator<I,O>
net.dv8tion.jda.internal.requests.restaction.operator.MapRestAction<I,O>
All Implemented Interfaces:
RestAction<O>

public class MapRestAction<I,O> extends RestActionOperator<I,O>
  • Constructor Details

  • Method Details

    • queue

      public void queue(@Nullable Consumer<? super O> 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

      public O complete(boolean shouldQueue) throws RateLimitedException
      Description copied from interface: RestAction
      Blocks the current Thread and awaits the completion of an RestAction.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 the shouldQueue is false. Use RestAction.complete() to avoid this Exception.
    • submit

      @Nonnull public CompletableFuture<O> submit(boolean shouldQueue)
      Description copied from interface: RestAction
      Submits a Request for execution and provides a CompletableFuture 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