File tree Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 1
1
## 2.13.0
2
2
3
3
- Fix type check and cast in SubscriptionStream's cancelOnError wrapper
4
+ - Fix ` StreamGroup.broadcast().close() ` to properly complete when all streams in the group close without being explicitly removed.
4
5
5
6
## 2.12.0
6
7
Original file line number Diff line number Diff line change @@ -289,7 +289,23 @@ class StreamGroup<T> implements Sink<Stream<T>> {
289
289
if (_closed) return _controller.done;
290
290
291
291
_closed = true ;
292
- if (_subscriptions.isEmpty) _controller.close ();
292
+
293
+ if (_subscriptions.isEmpty) {
294
+ _onIdleController? .add (null );
295
+ _onIdleController? .close ();
296
+ _controller.close ();
297
+ return _controller.done;
298
+ }
299
+
300
+ if (_controller.stream.isBroadcast) {
301
+ for (var entry in _subscriptions.entries.where ((e) => e.value == null )) {
302
+ try {
303
+ _subscriptions[entry.key] = _listenToStream (entry.key);
304
+ } catch (_) {
305
+ _subscriptions.remove (entry.key);
306
+ }
307
+ }
308
+ }
293
309
294
310
return _controller.done;
295
311
}
Original file line number Diff line number Diff line change @@ -491,6 +491,22 @@ void main() {
491
491
controller.add ('first' );
492
492
expect (streamGroup.close (), completes);
493
493
});
494
+
495
+ test ('completes close() when streams close without being removed' ,
496
+ () async {
497
+ var controller = StreamController .broadcast ();
498
+ var group = StreamGroup .broadcast ();
499
+ group.add (controller.stream);
500
+ var closeCompleted = false ;
501
+ group.close ().then ((_) => closeCompleted = true );
502
+
503
+ await flushMicrotasks ();
504
+ expect (closeCompleted, isFalse);
505
+
506
+ await controller.close ();
507
+ await flushMicrotasks ();
508
+ expect (closeCompleted, isTrue);
509
+ });
494
510
});
495
511
496
512
group ('regardless of type' , () {
You can’t perform that action at this time.
0 commit comments