File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed
Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -297,12 +297,24 @@ class StreamGroup<T> implements Sink<Stream<T>> {
297297 }
298298
299299 if (_controller.stream.isBroadcast) {
300- for (var entry in _subscriptions.entries.where ((e) => e.value == null )) {
300+ // For a broadcast group that's closed, we must listen to streams with
301+ // null subscriptions to detect when they complete. This ensures the
302+ // group itself can close once all its streams have closed.
303+ final streamsToRemove = < Stream <T >> [];
304+
305+ _subscriptions.updateAll ((stream, subscription) {
306+ if (subscription != null ) return subscription;
307+
301308 try {
302- _subscriptions[entry.key] = _listenToStream (entry.key);
303- } catch (_) {
304- _subscriptions.remove (entry.key);
309+ return _listenToStream (stream);
310+ } on Object {
311+ streamsToRemove.add (stream);
312+ return null ;
305313 }
314+ });
315+
316+ for (final stream in streamsToRemove) {
317+ _subscriptions.remove (stream);
306318 }
307319 }
308320
You can’t perform that action at this time.
0 commit comments