The Dart stream framework supports the single-subscription and broadcast streams in order to have different approaches depending on the required solution. Let's see the difference between single-subscription and broadcast streams.
A stream that allows you to have only one listener during the entire lifetime is called a single-subscription stream. You are not allowed to cancel and subscribe to the same stream again. The newly created stream starts generating events only after the subscription starts listening to them. It stops generating events after the subscription is canceled even if the stream can provide more. The single-subscription stream always delivers each event in the correct order to a listener.
A good usage example of a single-subscription stream is getting data from the file or server.
A stream that allows you to have multiple listeners during the entire lifetime is called the broadcast stream. You are allowed to subscribe or cancel the subscription at any time. A broadcast stream starts to generate events immediately after the creation if it ready, independent of whether any subscription is registered or not. This fact means that some portion of the events can be lost in a moment when no listener is registered. There is no guarantee that multiple listeners will get the event in the same order that they were registered. A broadcast stream only guarantees that each listener will get all the events in the correct order.
A good example of using the broadcast stream is the eventbus implementation that supports multiple listeners.
18.219.249.210