Add isClosed getters to StreamGroup and FutureGroup (#165)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 84938d0..421db06 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,8 @@
* Added `ChunkedStreamReader` for reading _chunked streams_ without managing
buffers.
+* Add `StreamGroup.isClosed` and `FutureGroup.isClosed` getters.
+
## 2.5.0
* Stable release for null safety.
diff --git a/lib/src/future_group.dart b/lib/src/future_group.dart
index 3a6291f..1742d6a 100644
--- a/lib/src/future_group.dart
+++ b/lib/src/future_group.dart
@@ -22,7 +22,9 @@
/// The number of futures that have yet to complete.
var _pending = 0;
- /// Whether [close] has been called.
+ /// Whether the group is closed, meaning that no more futures may be added.
+ bool get isClosed => _closed;
+
var _closed = false;
/// The future that fires once [close] has been called and all futures in the
diff --git a/lib/src/stream_group.dart b/lib/src/stream_group.dart
index 8c17ec2..c864987 100644
--- a/lib/src/stream_group.dart
+++ b/lib/src/stream_group.dart
@@ -32,6 +32,8 @@
late StreamController<T> _controller;
/// Whether the group is closed, meaning that no more streams may be added.
+ bool get isClosed => _closed;
+
var _closed = false;
/// The current state of the group.
diff --git a/pubspec.yaml b/pubspec.yaml
index 5bfe9b1..59ee5f2 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: async
-version: 2.6.0
+version: 2.6.0-dev
description: Utility functions and classes related to the 'dart:async' library.
repository: https://github.com/dart-lang/async
diff --git a/test/future_group_test.dart b/test/future_group_test.dart
index 22e90f8..c2b1f3f 100644
--- a/test/future_group_test.dart
+++ b/test/future_group_test.dart
@@ -26,7 +26,9 @@
test("completes once it's closed", () {
expect(futureGroup.future, completion(isEmpty));
+ expect(futureGroup.isClosed, isFalse);
futureGroup.close();
+ expect(futureGroup.isClosed, isTrue);
});
});
@@ -47,7 +49,9 @@
await flushMicrotasks();
expect(futureGroup.future, completes);
+ expect(futureGroup.isClosed, isFalse);
futureGroup.close();
+ expect(futureGroup.isClosed, isTrue);
});
test("completes to that future's value", () {
diff --git a/test/stream_group_test.dart b/test/stream_group_test.dart
index eadae19..43f9bfc 100644
--- a/test/stream_group_test.dart
+++ b/test/stream_group_test.dart
@@ -543,7 +543,9 @@
streamGroup.add(controller2.stream);
await flushMicrotasks();
+ expect(streamGroup.isClosed, isFalse);
streamGroup.close();
+ expect(streamGroup.isClosed, isTrue);
streamGroup.remove(controller1.stream);
await flushMicrotasks();