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 pub.error_group; | 5 library pub.error_group; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 /// An [ErrorGroup] entangles the errors of multiple [Future]s and [Stream]s | 9 /// An [ErrorGroup] entangles the errors of multiple [Future]s and [Stream]s |
10 /// with one another. This allows APIs to expose multiple [Future]s and | 10 /// with one another. This allows APIs to expose multiple [Future]s and |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 future._signalError(error, stackTrace); | 120 future._signalError(error, stackTrace); |
121 } | 121 } |
122 | 122 |
123 for (var stream in _streams) { | 123 for (var stream in _streams) { |
124 if (stream._isDone || stream._hasListeners) caught = true; | 124 if (stream._isDone || stream._hasListeners) caught = true; |
125 stream._signalError(error, stackTrace); | 125 stream._signalError(error, stackTrace); |
126 } | 126 } |
127 | 127 |
128 _isDone = true; | 128 _isDone = true; |
129 _done._signalError(error, stackTrace); | 129 _done._signalError(error, stackTrace); |
130 if (!caught && !_done._hasListeners) runAsync((){ throw error; }); | 130 if (!caught && !_done._hasListeners) scheduleMicrotask((){ throw error; }); |
131 } | 131 } |
132 | 132 |
133 /// Notifies [this] that one of its member [Future]s is complete. | 133 /// Notifies [this] that one of its member [Future]s is complete. |
134 void _signalFutureComplete(_ErrorGroupFuture future) { | 134 void _signalFutureComplete(_ErrorGroupFuture future) { |
135 if (_isDone) return; | 135 if (_isDone) return; |
136 | 136 |
137 _isDone = _futures.every((future) => future._isDone) && | 137 _isDone = _futures.every((future) => future._isDone) && |
138 _streams.every((stream) => stream._isDone); | 138 _streams.every((stream) => stream._isDone); |
139 if (_isDone) _doneCompleter.complete(); | 139 if (_isDone) _doneCompleter.complete(); |
140 } | 140 } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 void _signalError(var e, [StackTrace stackTrace]) { | 268 void _signalError(var e, [StackTrace stackTrace]) { |
269 if (_isDone) return; | 269 if (_isDone) return; |
270 _subscription.cancel(); | 270 _subscription.cancel(); |
271 // Call these asynchronously to work around issue 7913. | 271 // Call these asynchronously to work around issue 7913. |
272 new Future.value().then((_) { | 272 new Future.value().then((_) { |
273 _controller.addError(e, stackTrace); | 273 _controller.addError(e, stackTrace); |
274 _controller.close(); | 274 _controller.close(); |
275 }); | 275 }); |
276 } | 276 } |
277 } | 277 } |
OLD | NEW |