Chromium Code Reviews| Index: lib/src/future_group.dart |
| diff --git a/lib/src/future_group.dart b/lib/src/future_group.dart |
| index 81ba4fae78767787b172801b578ad7b94f0de079..21d677f9bd966203483d6cda08f2fd11594c8c7c 100644 |
| --- a/lib/src/future_group.dart |
| +++ b/lib/src/future_group.dart |
| @@ -35,6 +35,17 @@ class FutureGroup<T> implements Sink<Future<T>> { |
| Future<List<T>> get future => _completer.future; |
| final _completer = new Completer<List<T>>(); |
| + /// Whether this group is waiting on any futures. |
| + bool get isIdle => _pending == 0; |
| + |
| + /// A broadcast stream that emits a `null` event whenever the last pending |
| + /// future in this group completes. |
| + /// |
| + /// Once this group isn't waiting on any futures *and* [close] has been |
| + /// called, this stream will close. |
| + Stream get onIdle => _onIdleController.stream; |
| + final _onIdleController = new StreamController.broadcast(sync: true); |
|
Lasse Reichstein Nielsen
2015/07/02 09:18:35
Could it be worth it to only create this controlle
nweiz
2015/07/06 20:23:18
Done.
|
| + |
| /// The values emitted by the futures that have been added to the group, in |
| /// the order they were added. |
| /// |
| @@ -58,7 +69,12 @@ class FutureGroup<T> implements Sink<Future<T>> { |
| _pending--; |
| _values[index] = value; |
| - if (_pending == 0 && _closed) _completer.complete(_values); |
| + if (_pending != 0) return; |
| + _onIdleController.add(null); |
| + |
| + if (!_closed) return; |
| + _onIdleController.close(); |
| + _completer.complete(_values); |
| }).catchError((error, stackTrace) { |
| if (_completer.isCompleted) return; |
| _completer.completeError(error, stackTrace); |