cancel method

void cancel([
  1. Exception exception = const CancelledException()
])

Cancels all operations with this token.

An optional exception can be provided to give a cancellation reason.

Implementation

void cancel([Exception exception = const CancelledException()]) {
  if (_isCancelled) return;
  _isCancelled = true;
  _exception = exception;
  for (Cancellable cancellable in _attachedCancellables) {
    cancellable.onCancel(exception);
  }
  _attachedCancellables.clear();
}