-
public final class CancellationTokenPropagates notification that operations should be canceled.
Create an instance of
CancellationTokenSourceand pass the token returned fromCancellationTokenSource.tokento the asynchronous operation(s). CallCancellationTokenSource#cancel()to cancel the operations.A
CancellationTokencan only be cancelled once - it should not be passed to future operations once cancelled.
-
-
Field Summary
Fields Modifier and Type Field Description private final BooleanisCancellationRequested
-
Method Summary
Modifier and Type Method Description final BooleangetIsCancellationRequested()final CancellationTokenRegistrationregister(Runnable action)Registers a runnable that will be called when this CancellationToken is canceled. final UnitthrowIfCancellationRequested()StringtoString()-
-
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()
-
-
-
-