Victor Savkin
Victor Savkin

Reputation: 1789

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 that constructor is gone in M4.

Upvotes: 4

Views: 1504

Answers (1)

Chris Buckett
Chris Buckett

Reputation: 14388

Per this link:

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

With r21499 we removed the StreamController.broadcast constructor.

The StreamController.broadcast streams had nasty properties that could easily lead to missed events and similar hard-to-debug conditions. We initially added this class for the html-library, but ended up not needing it there. By removing this class we can have a much cleaner contract for Streams.

We still kept the asBroadcastStream method. Its behavior is slightly different and saner than the one of StreamController.broadcast. In most cases you can try to migrate to asBroadcastStream if you need to attach multiple listeners.

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

(But you might also want to keep an eye on this question: asBroadcastStream can't be called multiple times )

Upvotes: 6

Related Questions