Class AsyncRequest<T>
java.lang.Object
io.github.matyrobbrt.curseforgeapi.request.AsyncRequest<T>
- Type Parameters:
T
- the response type
An object used for async requests.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<U> AsyncRequest<Pair<T,
U>> and
(AsyncRequest<U> other) Merges this request with theother
one, making the new type of the request aPair
.static <T> AsyncRequest<T>
empty()
<U> AsyncRequest<U>
flatMap
(Function<? super T, AsyncRequest<U>> mapper) Intermediate operator that returns a modifiedAsyncRequest
.<U,
E extends Exception>
AsyncRequest<U>flatMapWithException
(ExceptionFunction<? super T, AsyncRequest<U>, E> mapper) Intermediate operator that returns a modifiedAsyncRequest
.get()
Completes this request by blocking the current thread until the value is returned, and then returning it.<U> AsyncRequest<U>
Maps this requestvoid
queue()
Queues the action for later completion.void
Queues the action for later completion.void
Queues the action for later completion.static void
setFutureExecutor
(Executor executor)
-
Constructor Details
-
AsyncRequest
-
-
Method Details
-
setFutureExecutor
-
empty
- Type Parameters:
T
-- Returns:
- an empty async request
-
map
Maps this request- Type Parameters:
U
- the new type of the request- Parameters:
mapper
- the mapper to use- Returns:
- the request
-
flatMap
Intermediate operator that returns a modifiedAsyncRequest
.- Type Parameters:
O
- The target output type- Parameters:
flatMap
- The mapping function to apply to the action result, must return anAsyncRequest
- 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 modifiedAsyncRequest
.
Opposed toflatMap(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 typeO
- The exception type thrown by the mapper- Parameters:
flatMap
- The mapping function to apply to the action result, must return anAsyncRequest
- Returns:
AsyncRequest
for the mapped type- See Also:
-
and
Merges this request with theother
one, making the new type of the request aPair
.- 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
ofT
andU
-
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
Queues the action for later completion.- Parameters:
onSuccess
- the consumer to run when the action succeeded
-
queue
Queues the action for later completion.- Parameters:
onSuccess
- the consumer to run when the action succeededonFailure
- the consumer to run when the action fails
-