W3cubDocs

/Dart 2

Stream<T>.fromIterable constructor

Stream<T>.fromIterable(Iterable<T> elements)

Creates a single-subscription stream that gets its data from elements.

The iterable is iterated when the stream receives a listener, and stops iterating if the listener cancels the subscription, or if the Iterator.moveNext method returns false or throws. Iteration is suspended while the stream subscription is paused.

If calling Iterator.moveNext on elements.iterator throws, the stream emits that error and then it closes. If reading Iterator.current on elements.iterator throws, the stream emits that error, but keeps iterating.

Implementation

factory Stream.fromIterable(Iterable<T> elements) {
  return new _GeneratedStreamImpl<T>(
      () => new _IterablePendingEvents<T>(elements));
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.5.0/dart-async/Stream/Stream.fromIterable.html