cancel method

Future cancel ({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.

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

Implementation

Future cancel({bool immediate: false}) {
  if (_isClosed) throw _failClosed();
  _isClosed = true;

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

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