Creating streams with multiple subscribers

What is the best way to create and use streams with multiple subscribers?

It used to be:

new StreamController.broadcast() 

But this constructor went to M4.

+4
source share
1 answer

By this link:

https://groups.google.com/a/dartlang.org/d/msg/misc/KJrKH5-bNkU/CjpIpEP_EpgJ

With r21499, we removed the StreamController.broadcast constructor.

StreamController.broadcast streams had unpleasant properties that could easily lead to missed events and similar difficult to debug conditions. We initially added this class for the html library, but in the end this is not necessary. By removing this class, we can have a much cleaner contract for Streams.

We saved the asBroadcastStream method. Its behavior is slightly different and cleaner than that of StreamController.broadcast. In most cases, you can try switching to asBroadcastStream if you need to connect multiple listeners.

So create a new stream and call asBroadcastStream() on it.

(But you can also follow up on this issue: asBroadcastStream cannot be called multiple times )

+6
source

All Articles