| 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 * | 180 * |
| 181 * Use [Completer] to create a Future and complete it later. | 181 * Use [Completer] to create a Future and complete it later. |
| 182 */ | 182 */ |
| 183 factory Future.value([value]) { | 183 factory Future.value([value]) { |
| 184 return new _Future<T>.immediate(value); | 184 return new _Future<T>.immediate(value); |
| 185 } | 185 } |
| 186 | 186 |
| 187 /** | 187 /** |
| 188 * A future that completes with an error in the next event-loop iteration. | 188 * A future that completes with an error in the next event-loop iteration. |
| 189 * | 189 * |
| 190 * Use [Completer] to create a Future and complete it later. | 190 * If [error] is `null`, it is replaced by a [NullThrownError]. |
| 191 * |
| 192 * Use [Completer] to create a future and complete it later. |
| 191 */ | 193 */ |
| 192 factory Future.error(Object error, [StackTrace stackTrace]) { | 194 factory Future.error(Object error, [StackTrace stackTrace]) { |
| 195 error = _nonNullError(error); |
| 193 if (!identical(Zone.current, _ROOT_ZONE)) { | 196 if (!identical(Zone.current, _ROOT_ZONE)) { |
| 194 AsyncError replacement = Zone.current.errorCallback(error, stackTrace); | 197 AsyncError replacement = Zone.current.errorCallback(error, stackTrace); |
| 195 if (replacement != null) { | 198 if (replacement != null) { |
| 196 error = replacement.error; | 199 error = _nonNullError(replacement.error); |
| 197 stackTrace = replacement.stackTrace; | 200 stackTrace = replacement.stackTrace; |
| 198 } | 201 } |
| 199 } | 202 } |
| 200 return new _Future<T>.immediateError(error, stackTrace); | 203 return new _Future<T>.immediateError(error, stackTrace); |
| 201 } | 204 } |
| 202 | 205 |
| 203 /** | 206 /** |
| 204 * Creates a future that runs its computation after a delay. | 207 * Creates a future that runs its computation after a delay. |
| 205 * | 208 * |
| 206 * The [computation] will be executed after the given [duration] has passed, | 209 * The [computation] will be executed after the given [duration] has passed, |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 /** | 659 /** |
| 657 * Whether the future has been completed. | 660 * Whether the future has been completed. |
| 658 */ | 661 */ |
| 659 bool get isCompleted; | 662 bool get isCompleted; |
| 660 } | 663 } |
| 661 | 664 |
| 662 // Helper function completing a _Future with error, but checking the zone | 665 // Helper function completing a _Future with error, but checking the zone |
| 663 // for error replacement first. | 666 // for error replacement first. |
| 664 void _completeWithErrorCallback(_Future result, error, stackTrace) { | 667 void _completeWithErrorCallback(_Future result, error, stackTrace) { |
| 665 AsyncError replacement = Zone.current.errorCallback(error, stackTrace); | 668 AsyncError replacement = Zone.current.errorCallback(error, stackTrace); |
| 666 if (replacement == null) { | 669 if (replacement != null) { |
| 667 result._completeError(error, stackTrace); | 670 error = _nonNullError(replacement.error); |
| 668 } else { | 671 stackTrace = replacement.stackTrace; |
| 669 result._completeError(replacement.error, replacement.stackTrace); | |
| 670 } | 672 } |
| 673 result._completeError(error, stackTrace); |
| 671 } | 674 } |
| 672 | 675 |
| 676 /** Helper function that converts `null` to a [NullThrownError]. */ |
| 677 Object _nonNullError(Object error) => |
| 678 (error != null) ? error : new NullThrownError(); |
| OLD | NEW |