Interface CancellationToken<E extends RuntimeException>
- Type Parameters:
E- the exception type surfaced bythrowIfCancellationRequested()andgetCancellationFuture()when cancellation is requested
Token that allows asynchronous code to observe cancellation requests.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceHandle for removing a previously registered cancellation callback. -
Method Summary
Modifier and TypeMethodDescriptiondefault CompletableFuture<Void> Future that completes exceptionally withEwhen cancellation has been requested.booleanReturns true after cancellation has been requested.static <E extends RuntimeException>
CancellationToken<E> none()A token that is never cancelled.Registers a callback to run when cancellation is requested, or immediately if already cancelled.voidThrowsEif cancellation has been requested.
-
Method Details
-
isCancellationRequested
boolean isCancellationRequested()Returns true after cancellation has been requested. -
throwIfCancellationRequested
void throwIfCancellationRequested() throws EThrowsEif cancellation has been requested.- Throws:
E
-
getCancellationFuture
Future that completes exceptionally withEwhen cancellation has been requested.Code waiting on external work can chain off this future to abort in-flight requests when cancellation is requested.
-
onCancel
Registers a callback to run when cancellation is requested, or immediately if already cancelled.- Returns:
- a handle that removes the callback if cancellation has not happened yet.
-
none
A token that is never cancelled.
-