Interface Task<T>
-
- Type Parameters:
T
- The result type
public interface Task<T>
Represents an asynchronous task.
Note: The underlying task may already be started.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
cancel()
Cancels the task and will emit aCancellationException
.T
get()
Blocks the current thread until the result is ready.boolean
isStarted()
Whether this task has started.Task<T>
onError(java.util.function.Consumer<? super java.lang.Throwable> callback)
Provide a callback for exception handling.Task<T>
onSuccess(java.util.function.Consumer<? super T> callback)
Provide a callback for success handling.
-
-
-
Method Detail
-
isStarted
boolean isStarted()
Whether this task has started.- Returns:
- True, if this task has already started.
-
onError
@Nonnull Task<T> onError(@Nonnull java.util.function.Consumer<? super java.lang.Throwable> callback)
Provide a callback for exception handling.
This is an asynchronous operation.The error will be logged regardless of your callback, this only exists to handle failures for other purposes.
- Parameters:
callback
- The error callback- Returns:
- The current Task instance for chaining
- Throws:
java.lang.IllegalArgumentException
- If null is provided
-
onSuccess
@Nonnull Task<T> onSuccess(@Nonnull java.util.function.Consumer<? super T> callback)
Provide a callback for success handling.
This is an asynchronous operation.- Parameters:
callback
- The success callback- Returns:
- The current Task instance for chaining
- Throws:
java.lang.IllegalArgumentException
- If null is provided
-
get
@Nonnull T get()
Blocks the current thread until the result is ready.
This will not work on the default JDA event thread because it might depend on other events to be processed, which could lead to a deadlock.- Returns:
- The result value
- Throws:
java.lang.UnsupportedOperationException
- If this is called on the default JDA event threadjava.util.concurrent.CompletionException
- If some exception occurred (such asTimeoutException
).java.util.concurrent.CancellationException
- If the request was cancelled
-
cancel
void cancel()
Cancels the task and will emit aCancellationException
.
-
-