Open sgrekhov opened 1 month ago
Summary: The issue reports that a stream created by Stream.multi()
is not always a multi-subscription stream when the source of MultiStreamController.addStream()
is a single-subscription stream, leading to a "Bad state" error when attempting to listen to the stream multiple times. The user suggests updating the Stream.multi()
documentation to reflect this behavior.
The documentation should probably be expanded.
The Stream.multi
stream can support a wide variety of behaviors, including being listend to multiple times, and the code that provides events can choose to limit what will work.
A "multi-subscription stream" here means a stream which you can call listen
on multiple times. The stream itself doesn't prevent that.
If the code that's supposed to provide events to the stream decides to throw during listen
, it gets what it asks for. That makes the stream behave like a single-subscription stream. But by that measure, a StreamController(onListen: () { throw "Nah-ah!"; })
is not a single-subscription stream either, but a zero-subscription stream.
More text is probably the way to go.
If nothing else then:
/// Creates a steam which can respond to multiple listeners.
///
/// Each call to [Stream.listen] on the created stream
/// will call [onListen] with a new
/// [MultiStreamController] which can be used to
/// send events to that one subscription.
According to
Stream.multi
documentation https://github.com/dart-lang/sdk/blob/0342791d3374446b32be4ed7ec795be0c88c40d9/sdk/lib/async/stream.dart#L398It's not quite true in the case when a source of
MultiStreamController.addStream()
is a single-subscription stream. For example:Is this expected? If yes, then, probably, it makes sense to reflect it in the
Stream.multi()
constructor documentation.cc @lrhn