DataStream<T>.fromStream constructor

DataStream<T>.fromStream(
  1. Stream<T> stream,
  2. T? initialValue, {
  3. Function? onError,
})

Creates a DataStream from a Stream. Data emitted by stream will also be emitted by this EventStream. Values can also be emitted 'manually' to this DataStream using regular methods. This DataStream will NOT be closed if stream is done: only the internal subscription will be cancelled when this DataStream is closed. If onError is provided, it will be called when an error is emitted by stream. Otherwise error events will be ignored.

Implementation

DataStream.fromStream(Stream<T> stream, super.initialValue, {Function? onError}) {
  _fromStreamSubscription = stream.listen(add, onError: onError ?? (e) {});
}