CancellationToken class
Propagates notification that operations should be canceled.
A CancellationToken may be created directly in an unchangeable
canceled or non-canceled state using the CancellationToken's constructors.
However, to have a CancellationToken that can change from a non-canceled
to a canceled state, CancellationTokenSource must be used.
CancellationTokenSource exposes the associated CancellationToken that may
be canceled by the source through its token
property.
Once canceled, a token may not transition to a non-canceled state, and a
token whose CanBeCanceled
is false will never change to one that can be
canceled.
Constructors
- CancellationToken.new([bool canceled = false])
-
Creates a CancellationToken that can be canceled.
factory
Properties
- canBeCanceled → bool
-
Gets whether this token is capable of being in the canceled state.
no setter
- hashCode → int
-
The hash code for this object.
no setteroverride
- isCancellationRequested → bool
-
Gets whether cancellation has been requested for this token.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
register(
CallbackRegistration? callback, [Object? state]) → CancellationTokenRegistration - Registers a callback that will be called when the CancellationToken is canceled.
-
throwIfCancellationRequested(
) → void -
Throws a
OperationCanceledException
if this token has had cancellation requested. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override
Static Properties
- none → CancellationToken
-
Returns an empty CancellationToken value.
no setter