FutureStream<T> constructor

FutureStream<T>(Future<Stream<T>> future, { bool broadcast: false })

Implementation

FutureStream(Future<Stream<T>> future, {bool broadcast: false}) {
  _future = future.then(_identity, onError: (e, stackTrace) {
    // Since [controller] is synchronous, it's likely that emitting an error
    // will cause it to be cancelled before we call close.
    if (_controller != null) {
      _controller.addError(e, stackTrace);
      _controller.close();
    }
    _controller = null;
  });

  if (broadcast == true) {
    _controller = new StreamController.broadcast(
        sync: true, onListen: _onListen, onCancel: _onCancel);
  } else {
    _controller = new StreamController(
        sync: true, onListen: _onListen, onCancel: _onCancel);
  }
}