Cancellable mixin

A mixin for making a class cancellable using a CancellationToken.

This does not handle attaching to and detatching from the token.

Classes using this mixin should call maybeAttach(token) to attach to the token when they're created, and call token.detatch(this) on the token once complete to prevent memory leaks.

Cancellables can have nullable tokens to make them optionally cancellable. In these cases, you can call maybeAttach(token) as usual to attach to the token if there is one, and use token?.detach(this) to detach when done.

Mixin Applications

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

maybeAttach(CancellationToken? token) bool
Attaches to the CancellationToken only if it hasn't already been cancelled. If the token has already been cancelled, onCancel is called instead.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onCancel(Exception cancelException, [StackTrace? stackTrace]) → void
Called when the attached token is cancelled.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited