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 error_group; | 5 library error_group; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
| 9 import 'utils.dart'; |
| 10 |
9 /// An [ErrorGroup] entangles the errors of multiple [Future]s and [Stream]s | 11 /// 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 | 12 /// with one another. This allows APIs to expose multiple [Future]s and |
11 /// [Stream]s that have identical error conditions without forcing API consumers | 13 /// [Stream]s that have identical error conditions without forcing API consumers |
12 /// to attach error handling to objects they don't care about. | 14 /// to attach error handling to objects they don't care about. |
13 /// | 15 /// |
14 /// To use an [ErrorGroup], register [Future]s and [Stream]s with it using | 16 /// To use an [ErrorGroup], register [Future]s and [Stream]s with it using |
15 /// [registerFuture] and [registerStream]. These methods return wrapped versions | 17 /// [registerFuture] and [registerStream]. These methods return wrapped versions |
16 /// of the [Future]s and [Stream]s, which should then be used in place of the | 18 /// of the [Future]s and [Stream]s, which should then be used in place of the |
17 /// originals. For example: | 19 /// originals. For example: |
18 /// | 20 /// |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 onDone: onDone, | 255 onDone: onDone, |
254 unsubscribeOnError: true); | 256 unsubscribeOnError: true); |
255 } | 257 } |
256 | 258 |
257 /// Signal that an error from [_group] should be propagated through [this], | 259 /// Signal that an error from [_group] should be propagated through [this], |
258 /// unless it's already complete. | 260 /// unless it's already complete. |
259 void _signalError(AsyncError e) { | 261 void _signalError(AsyncError e) { |
260 if (_isDone) return; | 262 if (_isDone) return; |
261 _subscription.cancel(); | 263 _subscription.cancel(); |
262 // Call these asynchronously to work around issue 7913. | 264 // Call these asynchronously to work around issue 7913. |
263 new Future.immediate(null).then((_) { | 265 defer(() { |
264 _controller.signalError(e.error, e.stackTrace); | 266 _controller.signalError(e.error, e.stackTrace); |
265 _controller.close(); | 267 _controller.close(); |
266 }); | 268 }); |
267 } | 269 } |
268 } | 270 } |
OLD | NEW |