Reputation: 4009
Searching for a way to combine multiple streams into single stream but add each stream in different time without dropping the stream listeners.
My end goal is many to many that join in different times.
Example:
A and B Streams Join.
E and F start listen to D.
B send data that reach E and F.
A send data that reach E and F.
G start listen to D.
C Stream join.
A send data that reach E and F and G.
C send data that reach E and F and G.
Found that the right side (multiple listeners at different times) can be done by using BehaviorSubject
but you cant add to it more streams without closing the last one.
And I found a lot of ways to marge streams but you have to marge all the streams at the same times and there is no way to add new one to the existing ones.
If we find a way to combine multiple streams at different times without drooping the listener we can use it like this since D can be used with BehaviorSubject
Upvotes: 1
Views: 578
Reputation: 4009
StreamGroup.broadcast
can do this, it is acting as H+D in my second picture.
It can
Please add async to your packages for StreamGroup
.
Example:
StreamGroup<int> streamGroup = StreamGroup.broadcast();
Than to add a stream use:
streamGroup.add(streamToAdd);
To listen to it use:
streamGroup.stream.listen((event) { })
Upvotes: 1