Class AsyncRequest<T>

java.lang.Object
io.github.matyrobbrt.curseforgeapi.request.AsyncRequest<T>
Type Parameters:
T - the response type

public final class AsyncRequest<T> extends Object
An object used for async requests.
  • Constructor Details

  • Method Details

    • setFutureExecutor

      public static void setFutureExecutor(Executor executor)
    • empty

      public static <T> AsyncRequest<T> empty()
      Type Parameters:
      T -
      Returns:
      an empty async request
    • map

      public <U> AsyncRequest<U> map(Function<? super T,? super U> mapper)
      Maps this request
      Type Parameters:
      U - the new type of the request
      Parameters:
      mapper - the mapper to use
      Returns:
      the request
    • flatMap

      public <U> AsyncRequest<U> flatMap(Function<? super T,AsyncRequest<U>> mapper)
      Intermediate operator that returns a modified AsyncRequest.
      Type Parameters:
      O - The target output type
      Parameters:
      flatMap - The mapping function to apply to the action result, must return an AsyncRequest
      Returns:
      AsyncRequest for the mapped type
      See Also:
    • flatMapWithException

      public <U, E extends Exception> AsyncRequest<U> flatMapWithException(ExceptionFunction<? super T,AsyncRequest<U>,E> mapper)
      Intermediate operator that returns a modified AsyncRequest.
      Opposed to flatMap(Function), this method allows the mapper to throw exceptions, which will be caught and a failed future will be thrown in such cases.
      Type Parameters:
      O - The target output type
      O - The exception type thrown by the mapper
      Parameters:
      flatMap - The mapping function to apply to the action result, must return an AsyncRequest
      Returns:
      AsyncRequest for the mapped type
      See Also:
    • and

      public <U> AsyncRequest<Pair<T,U>> and(AsyncRequest<U> other)
      Merges this request with the other one, making the new type of the request a Pair.
      Type Parameters:
      U - the type of the other request
      Parameters:
      other - the request to merge with
      Returns:
      a new request, whose type is a Pair of T and U
    • get

      Completes this request by blocking the current thread until the value is returned, and then returning it.
      Returns:
      the value returned by the request
      Throws:
      InterruptedException
      ExecutionException
    • queue

      public void queue()
      Queues the action for later completion.
    • queue

      public void queue(Consumer<? super T> onSuccess)
      Queues the action for later completion.
      Parameters:
      onSuccess - the consumer to run when the action succeeded
    • queue

      public void queue(Consumer<? super T> onSuccess, Consumer<? super Throwable> onFailure)
      Queues the action for later completion.
      Parameters:
      onSuccess - the consumer to run when the action succeeded
      onFailure - the consumer to run when the action fails