-
public final class CancellationToken
Propagates notification that operations should be canceled.
Create an instance of
CancellationTokenSource
and pass the token returned fromCancellationTokenSource.token
to the asynchronous operation(s). CallCancellationTokenSource#cancel()
to cancel the operations.A
CancellationToken
can only be cancelled once - it should not be passed to future operations once cancelled.
-
-
Field Summary
Fields Modifier and Type Field Description private final Boolean
isCancellationRequested
-
Method Summary
Modifier and Type Method Description final Boolean
getIsCancellationRequested()
final CancellationTokenRegistration
register(Runnable action)
Registers a runnable that will be called when this CancellationToken is canceled. final Unit
throwIfCancellationRequested()
String
toString()
-
-
Method Detail
-
getIsCancellationRequested
final Boolean getIsCancellationRequested()
-
register
final CancellationTokenRegistration register(Runnable action)
Registers a runnable that will be called when this CancellationToken is canceled. If this token is already in the canceled state, the runnable will be run immediately and synchronously.
- Parameters:
action
- the runnable to be run when the token is cancelled.
-
throwIfCancellationRequested
final Unit throwIfCancellationRequested()
-
-
-
-