cancel method Null safety

Future? cancel(
  1. {bool immediate = false}

Cancels the underlying event source.

If immediate is false (the default), the cancel operation waits until all previously requested events have been processed, then it cancels the subscription providing the events.

If immediate is true, the source is instead canceled immediately. Any pending events are completed as though the underlying stream had closed.

The returned future completes with the result of calling cancel on the subscription to the source stream.

After calling cancel, no further events can be requested. None of lookAhead, next, peek, rest, skip, take or cancel may be called again.


Future? cancel({bool immediate = false}) {
  _isClosed = true;

  if (!immediate) {
    var request = _CancelRequest<T>(this);
    return request.future;

  if (_isDone && _eventQueue.isEmpty) return Future.value();
  return _cancel();