FutureStream<T> constructor

FutureStream<T>(
  1. Future<Stream<T>> future, {
  2. 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.
    _controller?.addError(e, stackTrace);
    _controller?.close();
    _controller = null;
  });

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