Skip to content

Commit 12df45c

Browse files
committed
1.3.0: fix #2
1 parent 682b124 commit 12df45c

File tree

5 files changed

+57
-16
lines changed

5 files changed

+57
-16
lines changed

.idea/workspace.xml

Lines changed: 30 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.3.0 - Sep 29, 2020
2+
3+
- Bugfix: `Uncaught Error: Bad state: Cannot add event after closing`.
4+
15
## 1.2.0 - Aug 15, 2020
26

37
- Updated: `constructor` allow only **`Sink | StreamSubscription`** type.

lib/src/disposebag_base.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ class DisposeBag {
170170
return pairs.map((pair) => pair.second);
171171
}
172172

173-
final sinks = await _disposeByType<Sink>();
174173
final subscriptions = await _disposeByType<StreamSubscription>();
174+
final sinks = await _disposeByType<Sink>();
175175
final resources = {...sinks, ...subscriptions};
176176

177177
_resources.removeAll(resources);

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: disposebag
22
description: A package to help disposing Streams and closing Sinks easily.
3-
version: 1.2.0
3+
version: 1.3.0
44
homepage: https://github.com/hoc081098/disposebag.git
55
repository: https://github.com/hoc081098/disposebag.git
66
issue_tracker: https://github.com/hoc081098/disposebag/issues

test/disposebag_test.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,27 @@ void main() {
368368
await disposeBag.add(mockStreamSubscription);
369369
expect(await disposeBag.clear(), false);
370370
});
371+
372+
test('issue #2', () async {
373+
final bag = DisposeBag();
374+
375+
final controller = StreamController<int>(
376+
onCancel: () => Future.delayed(
377+
const Duration(milliseconds: 10),
378+
),
379+
);
380+
381+
await controller.disposedBy(bag);
382+
await controller.stream.listen(null).disposedBy(bag);
383+
384+
await Stream.periodic(const Duration(milliseconds: 1), (i) => i)
385+
.map((i) => i + 1)
386+
.where((i) => i.isEven)
387+
.listen(controller.add)
388+
.disposedBy(bag);
389+
390+
await bag.dispose();
391+
});
371392
});
372393

373394
group('Extensions', () {

0 commit comments

Comments
 (0)