OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of dart.async; | 5 part of dart.async; |
6 | 6 |
7 /** | 7 /** |
8 * An object representing a delayed computation. | 8 * An object representing a delayed computation. |
9 * | 9 * |
10 * A [Future] is used to represent a potential value, or error, | 10 * A [Future] is used to represent a potential value, or error, |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 remaining++; | 315 remaining++; |
316 } | 316 } |
317 if (remaining == 0) { | 317 if (remaining == 0) { |
318 return new Future.value(const []); | 318 return new Future.value(const []); |
319 } | 319 } |
320 values = new List/*<T>*/(remaining); | 320 values = new List/*<T>*/(remaining); |
321 } catch (e, st) { | 321 } catch (e, st) { |
322 // The error must have been thrown while iterating over the futures | 322 // The error must have been thrown while iterating over the futures |
323 // list, or while installing a callback handler on the future. | 323 // list, or while installing a callback handler on the future. |
324 if (remaining == 0 || eagerError) { | 324 if (remaining == 0 || eagerError) { |
325 // Just complete the error immediately. | 325 // Throw a new Future.error. |
326 result._completeError(e, st); | 326 // Don't just call `result._completeError` since that would propagate |
| 327 // the error too eagerly, not giving the callers time to install |
| 328 // error handlers. |
| 329 // Also, don't use `_asyncCompleteError` since that one doesn't give |
| 330 // zones the chance to intercept the error. |
| 331 return new Future.error(e, st); |
327 } else { | 332 } else { |
328 // Don't allocate a list for values, thus indicating that there was an | 333 // Don't allocate a list for values, thus indicating that there was an |
329 // error. | 334 // error. |
330 // Set error to the caught exception. | 335 // Set error to the caught exception. |
331 error = e; | 336 error = e; |
332 stackTrace = st; | 337 stackTrace = st; |
333 } | 338 } |
334 } | 339 } |
335 return result; | 340 return result; |
336 } | 341 } |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 if (replacement != null) { | 780 if (replacement != null) { |
776 error = _nonNullError(replacement.error); | 781 error = _nonNullError(replacement.error); |
777 stackTrace = replacement.stackTrace; | 782 stackTrace = replacement.stackTrace; |
778 } | 783 } |
779 result._completeError(error, stackTrace); | 784 result._completeError(error, stackTrace); |
780 } | 785 } |
781 | 786 |
782 /** Helper function that converts `null` to a [NullThrownError]. */ | 787 /** Helper function that converts `null` to a [NullThrownError]. */ |
783 Object _nonNullError(Object error) => | 788 Object _nonNullError(Object error) => |
784 (error != null) ? error : new NullThrownError(); | 789 (error != null) ? error : new NullThrownError(); |
OLD | NEW |