diff --git a/pkgs/async/CHANGELOG.md b/pkgs/async/CHANGELOG.md index 102ad59f..2c5a3ebb 100644 --- a/pkgs/async/CHANGELOG.md +++ b/pkgs/async/CHANGELOG.md @@ -4,6 +4,9 @@ easier to implement custom sinks. * Improve performance for `ChunkedStreamReader` by creating fewer internal sublists and specializing to create views for `Uint8List` chunks. +* Don't ignore broadcast streams added to a `StreamGroup` that doesn't have an + active listener but previously had listeners and contains a single + subscription inner stream. ## 2.7.0 diff --git a/pkgs/async/lib/src/stream_group.dart b/pkgs/async/lib/src/stream_group.dart index f7819bfd..c8414f49 100644 --- a/pkgs/async/lib/src/stream_group.dart +++ b/pkgs/async/lib/src/stream_group.dart @@ -192,7 +192,7 @@ class StreamGroup implements Sink> { // If this is a broadcast group and this isn't the first time it's been // listened to, there may still be some subscriptions to // single-subscription streams. - if (entry.value != null) return; + if (entry.value != null) continue; var stream = entry.key; try { diff --git a/pkgs/async/test/stream_group_test.dart b/pkgs/async/test/stream_group_test.dart index 11c66c1e..256056e6 100644 --- a/pkgs/async/test/stream_group_test.dart +++ b/pkgs/async/test/stream_group_test.dart @@ -417,6 +417,24 @@ void main() { expect(controller.hasListener, isTrue); }); + test( + 'listens on streams that follow single-subscription streams when ' + 'relistening after a cancel', () async { + var controller1 = StreamController(); + streamGroup.add(controller1.stream); + streamGroup.stream.listen(null).cancel(); + + var controller2 = StreamController(); + streamGroup.add(controller2.stream); + + var emitted = []; + streamGroup.stream.listen(emitted.add); + controller1.add('one'); + controller2.add('two'); + await flushMicrotasks(); + expect(emitted, ['one', 'two']); + }); + test('never cancels single-subscription streams', () async { var subscription = streamGroup.stream.listen(null);