Package net.dv8tion.jda.core.requests
Interface RequestFuture<T>
-
- Type Parameters:
T
- The completion type for this Future
- All Superinterfaces:
java.util.concurrent.CompletionStage<T>
,java.util.concurrent.Future<T>
- All Known Implementing Classes:
Promise
,RestFuture
public interface RequestFuture<T> extends java.util.concurrent.Future<T>, java.util.concurrent.CompletionStage<T>
Future allowing for use of continuations.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static <F extends java.util.concurrent.Future<?> & java.util.concurrent.CompletionStage<?>>
java.util.concurrent.CompletableFuture<java.lang.Void>allOf(java.util.Collection<F> cfs)
Returns a new CompletableFuture that is completed when all of the given Futures complete.static java.util.concurrent.CompletableFuture<java.lang.Void>
allOf(RequestFuture<?>... cfs)
Returns a new CompletableFuture that is completed when all of the given RequestFutures complete.static <F extends java.util.concurrent.Future<?> & java.util.concurrent.CompletionStage<?>>
java.util.concurrent.CompletableFuture<java.lang.Object>anyOf(java.util.Collection<F> cfs)
Returns a new CompletableFuture that is completed when any of the given Futures complete, with the same result.static java.util.concurrent.CompletableFuture<java.lang.Object>
anyOf(RequestFuture<?>... cfs)
Returns a new CompletableFuture that is completed when any of the given RequestFutures complete, with the same result.T
getNow(T valueIfAbsent)
Returns the result value (or throws any encountered exception) if completed, else returns the given valueIfAbsent.int
getNumberOfDependents()
Returns the estimated number of RequestFutures whose completions are awaiting completion of this RequestFuture.boolean
isCompletedExceptionally()
Returnstrue
if this RequestFuture completed exceptionally, in any way.T
join()
Returns the result value when complete, or throws an (unchecked) exception if completed exceptionally.java.util.concurrent.CompletableFuture<T>
toCompletableFuture()
This method is unsupported by the current implementation!-
Methods inherited from interface java.util.concurrent.CompletionStage
acceptEither, acceptEitherAsync, acceptEitherAsync, applyToEither, applyToEitherAsync, applyToEitherAsync, exceptionally, handle, handleAsync, handleAsync, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, whenComplete, whenCompleteAsync, whenCompleteAsync
-
-
-
-
Method Detail
-
allOf
static java.util.concurrent.CompletableFuture<java.lang.Void> allOf(RequestFuture<?>... cfs)
Returns a new CompletableFuture that is completed when all of the given RequestFutures complete. If any of the given RequestFutures complete exceptionally, then the returned CompletableFuture also does so, with a CompletionException holding this exception as its cause. Otherwise, the results, if any, of the given RequestFutures are not reflected in the returned CompletableFuture, but may be obtained by inspecting them individually. If no RequestFutures are provided, returns a CompletableFuture completed with the valuenull
.Among the applications of this method is to await completion of a set of independent RequestFutures before continuing a program, as in:
RequestFuture.allOf(c1, c2, c3).join();
.- Parameters:
cfs
- the RequestFutures- Returns:
- a new CompletableFuture that is completed when all of the given RequestFutures complete
- Throws:
java.lang.IllegalArgumentException
- if the array or any of its elements arenull
- See Also:
CompletableFuture.allOf(...)
-
allOf
static <F extends java.util.concurrent.Future<?> & java.util.concurrent.CompletionStage<?>> java.util.concurrent.CompletableFuture<java.lang.Void> allOf(java.util.Collection<F> cfs)
Returns a new CompletableFuture that is completed when all of the given Futures complete. If any of the given Futures complete exceptionally, then the returned CompletableFuture also does so, with a CompletionException holding this exception as its cause. Otherwise, the results, if any, of the given RequestFutures are not reflected in the returned CompletableFuture, but may be obtained by inspecting them individually. If no Futures are provided, returns a CompletableFuture completed with the valuenull
.Among the applications of this method is to await completion of a set of independent RequestFutures before continuing a program, as in:
RequestFuture.allOf(c1, c2, c3).join();
.- Type Parameters:
F
- the future implementation- Parameters:
cfs
- the Futures- Returns:
- a new CompletableFuture that is completed when all of the given Futures complete
- Throws:
java.lang.IllegalArgumentException
- if the collection or any of its elements arenull
- See Also:
CompletableFuture.allOf(...)
-
anyOf
static java.util.concurrent.CompletableFuture<java.lang.Object> anyOf(RequestFuture<?>... cfs)
Returns a new CompletableFuture that is completed when any of the given RequestFutures complete, with the same result. Otherwise, if it completed exceptionally, the returned CompletableFuture also does so, with a CompletionException holding this exception as its cause. If no RequestFutures are provided, returns an incomplete CompletableFuture.- Parameters:
cfs
- the RequestFutures- Returns:
- a new CompletableFuture that is completed with the result or exception of any of the given RequestFutures when one completes
- Throws:
java.lang.IllegalArgumentException
- if the array or any of its elements arenull
- See Also:
CompletableFuture.anyOf(...)
-
anyOf
static <F extends java.util.concurrent.Future<?> & java.util.concurrent.CompletionStage<?>> java.util.concurrent.CompletableFuture<java.lang.Object> anyOf(java.util.Collection<F> cfs)
Returns a new CompletableFuture that is completed when any of the given Futures complete, with the same result. Otherwise, if it completed exceptionally, the returned CompletableFuture also does so, with a CompletionException holding this exception as its cause. If no Futures are provided, returns an incomplete CompletableFuture.- Type Parameters:
F
- the future implementation- Parameters:
cfs
- the Futures- Returns:
- a new CompletableFuture that is completed with the result or exception of any of the given Futures when one completes
- Throws:
java.lang.IllegalArgumentException
- if the collection or any of its elements arenull
- See Also:
CompletableFuture.anyOf(...)
-
join
T join()
Returns the result value when complete, or throws an (unchecked) exception if completed exceptionally. To better conform with the use of common functional forms, if a computation involved in the completion of this CompletableFuture threw an exception, this method throws an (unchecked)CompletionException
with the underlying exception as its cause.- Returns:
- the result value
- Throws:
java.util.concurrent.CancellationException
- if the computation was cancelledjava.util.concurrent.CompletionException
- if this future completed exceptionally or a completion computation threw an exception
-
getNow
T getNow(T valueIfAbsent)
Returns the result value (or throws any encountered exception) if completed, else returns the given valueIfAbsent.- Parameters:
valueIfAbsent
- the value to return if not completed- Returns:
- the result value, if completed, else the given valueIfAbsent
- Throws:
java.util.concurrent.CancellationException
- if the computation was cancelledjava.util.concurrent.CompletionException
- if this future completed exceptionally or a completion computation threw an exception
-
isCompletedExceptionally
boolean isCompletedExceptionally()
Returnstrue
if this RequestFuture completed exceptionally, in any way. Possible causes include cancellation, explicit invocation ofcompleteExceptionally
, and abrupt termination of a CompletionStage action.- Returns:
true
if this RequestFuture completed exceptionally
-
getNumberOfDependents
int getNumberOfDependents()
Returns the estimated number of RequestFutures whose completions are awaiting completion of this RequestFuture. This method is designed for use in monitoring system state, not for synchronization control.- Returns:
- the number of dependent RequestFutures
-
-