cancel method

void cancel([
  1. String? reason
])

Implementation

void cancel([String? reason]) {
  if (_cancelled) return;
  _cancelled = true;
  _reason = reason ?? 'cancelled';
  unawaited(_subscription?.cancel());
  _subscription = null;
  // Listeners run synchronously, so by the time cancel() returns every run
  // holding this token has been answered and none can deliver a value.
  for (final void Function() listener
      in List<void Function()>.of(_listeners)) {
    listener();
  }
  _listeners.clear();
  _done.complete();
}