Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library async.future_group; | |
| 6 | |
| 7 import 'dart:async'; | 5 import 'dart:async'; |
| 8 | 6 |
| 9 /// A collection of futures waits until all added [Future]s complete. | 7 /// A collection of futures waits until all added [Future]s complete. |
| 10 /// | 8 /// |
| 11 /// Futures are added to the group with [add]. Once you're finished adding | 9 /// Futures are added to the group with [add]. Once you're finished adding |
| 12 /// futures, signal that by calling [close]. Then, once all added futures have | 10 /// futures, signal that by calling [close]. Then, once all added futures have |
| 13 /// completed, [future] will complete with a list of values from the futures in | 11 /// completed, [future] will complete with a list of values from the futures in |
| 14 /// the group, in the order they were added. | 12 /// the group, in the order they were added. |
| 15 /// | 13 /// |
| 16 /// If any added future completes with an error, [future] will emit that error | 14 /// If any added future completes with an error, [future] will emit that error |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 28 var _closed = false; | 26 var _closed = false; |
| 29 | 27 |
| 30 /// The future that fires once [close] has been called and all futures in the | 28 /// The future that fires once [close] has been called and all futures in the |
| 31 /// group have completed. | 29 /// group have completed. |
| 32 /// | 30 /// |
| 33 /// This will also complete with an error if any of the futures in the group | 31 /// This will also complete with an error if any of the futures in the group |
| 34 /// fails, regardless of whether [close] was called. | 32 /// fails, regardless of whether [close] was called. |
| 35 Future<List<T>> get future => _completer.future; | 33 Future<List<T>> get future => _completer.future; |
| 36 final _completer = new Completer<List<T>>(); | 34 final _completer = new Completer<List<T>>(); |
| 37 | 35 |
| 38 /// Whether this group is waiting on any futures. | 36 /// Returns `true` if this group isn't waiting on any futures. |
|
Lasse Reichstein Nielsen
2016/03/08 10:40:37
A getter is no different from a (final) field.
I'd
nweiz
2016/03/08 20:23:39
Done.
| |
| 39 bool get isIdle => _pending == 0; | 37 bool get isIdle => _pending == 0; |
| 40 | 38 |
| 41 /// A broadcast stream that emits a `null` event whenever the last pending | 39 /// A broadcast stream that emits a `null` event whenever the last pending |
| 42 /// future in this group completes. | 40 /// future in this group completes. |
| 43 /// | 41 /// |
| 44 /// Once this group isn't waiting on any futures *and* [close] has been | 42 /// Once this group isn't waiting on any futures *and* [close] has been |
| 45 /// called, this stream will close. | 43 /// called, this stream will close. |
| 46 Stream get onIdle { | 44 Stream get onIdle { |
| 47 if (_onIdleController == null) { | 45 if (_onIdleController == null) { |
| 48 _onIdleController = new StreamController.broadcast(sync: true); | 46 _onIdleController = new StreamController.broadcast(sync: true); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 /// Signals to the group that the caller is done adding futures, and so | 87 /// Signals to the group that the caller is done adding futures, and so |
| 90 /// [future] should fire once all added futures have completed. | 88 /// [future] should fire once all added futures have completed. |
| 91 void close() { | 89 void close() { |
| 92 _closed = true; | 90 _closed = true; |
| 93 if (_pending != 0) return; | 91 if (_pending != 0) return; |
| 94 if (_completer.isCompleted) return; | 92 if (_completer.isCompleted) return; |
| 95 _completer.complete(_values); | 93 _completer.complete(_values); |
| 96 } | 94 } |
| 97 } | 95 } |
| 98 | 96 |
| OLD | NEW |