attach method

void attach(
  1. Cancellable cancellable
)

Attaches a Cancellable to this token.

Before attaching to a CancellationToken, you should check if it's already been cancelled by using isCancelled.

Implementation

void attach(Cancellable cancellable) {
  assert(
    !isCancelled,
    'Attampted to attach to a $runtimeType that has already been cancelled.\n'
    'Before calling attach() you should check isCancelled.',
  );
  if (!isCancelled && !_attachedCancellables.contains(cancellable)) {
    _attachedCancellables.add(cancellable);
  }
}