split method

Stream<T> split ()

Returns a single-subscription stream that's a copy of the input stream.

This will throw a StateError if close has been called.

Implementation

Stream<T> split() {
  if (_isClosed) {
    throw new StateError("Can't call split() on a closed StreamSplitter.");
  }

  var controller = new StreamController<T>(
      onListen: _onListen, onPause: _onPause, onResume: _onResume);
  controller.onCancel = () => _onCancel(controller);

  for (var result in _buffer) {
    result.addTo(controller);
  }

  if (_isDone) {
    _closeGroup.add(controller.close());
  } else {
    _controllers.add(controller);
  }

  return controller.stream;
}