OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 future_group; | 5 library future_group; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 /// A completer that waits until all added [Future]s complete. | 9 /// A completer that waits until all added [Future]s complete. |
10 // TODO(rnystrom): Copied from web_components. Remove from here when it gets | 10 // TODO(rnystrom): Copied from web_components. Remove from here when it gets |
(...skipping 16 matching lines...) Expand all Loading... |
27 futures.add(task.then((value) { | 27 futures.add(task.then((value) { |
28 if (completed) return; | 28 if (completed) return; |
29 | 29 |
30 _pending--; | 30 _pending--; |
31 _values.add(value); | 31 _values.add(value); |
32 | 32 |
33 if (_pending <= 0) { | 33 if (_pending <= 0) { |
34 completed = true; | 34 completed = true; |
35 _completer.complete(_values); | 35 _completer.complete(_values); |
36 } | 36 } |
37 }).catchError((e) { | 37 }).catchError((error) { |
38 if (completed) return; | 38 if (completed) return; |
39 | 39 |
40 completed = true; | 40 completed = true; |
41 _completer.completeError(e.error, e.stackTrace); | 41 _completer.completeError(error); |
42 })); | 42 })); |
43 | 43 |
44 return task; | 44 return task; |
45 } | 45 } |
46 | 46 |
47 Future<List> get future => _completer.future; | 47 Future<List> get future => _completer.future; |
48 } | 48 } |
49 | 49 |
OLD | NEW |