setSourceStream method Null safety
- Stream<
T> sourceStream
Set a stream as the source of events for the StreamCompleter's stream.
The completer's stream
will act exactly as sourceStream
.
If the source stream is set before stream is listened to,
the listen call on stream is forwarded directly to sourceStream
.
If stream is listened to before setting the source stream, an intermediate subscription is created. It looks like a completely normal subscription, and can be paused or canceled, but it won't produce any events until a source stream is provided.
If the stream
subscription is canceled before a source stream is set,
the source stream will be listened to and immediately canceled again.
Otherwise, when the source stream is then set, it is immediately listened to, and its events are forwarded to the existing subscription.
Any one of setSourceStream, setEmpty, and setError may be called at most once. Trying to call any of them again will fail.
Implementation
void setSourceStream(Stream<T> sourceStream) {
if (_stream._isSourceStreamSet) {
throw StateError('Source stream already set');
}
_stream._setSourceStream(sourceStream);
}