attach method

  1. @override
void attach(
  1. Cancellable cancellable
)
override

Attaches a Cancellable to this token.

If this token isn't attached to any other cancellables, it will also attach itself to the merged tokens.

Implementation

@override
void attach(Cancellable cancellable) {
  _updateCancellationStatus();
  assert(
    !isCancelled,
    'Attampted to attach to a $runtimeType that has already been cancelled.\n'
    'Before calling attach() you should check isCancelled.',
  );
  if (!isCancelled) {
    if (_attachedCancellables.isEmpty) {
      for (final CancellationToken token in _tokens) {
        token.attach(this);
      }
    }
    if (!_attachedCancellables.contains(cancellable)) {
      _attachedCancellables.add(cancellable);
    }
  }
}