Chromium Code Reviews| 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 * The [error] must not be `null`. |
| 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 if (error == null) throw new ArgumentError("Error must not be null"); | |
|
floitsch
2014/09/24 12:59:14
Or make it an asynchronous "NullThrownError" ?
| |
| 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 = replacement.error; |
| 200 if (error == null) error = new NullThrownError(); | |
| 197 stackTrace = replacement.stackTrace; | 201 stackTrace = replacement.stackTrace; |
| 198 } | 202 } |
| 199 } | 203 } |
| 200 return new _Future<T>.immediateError(error, stackTrace); | 204 return new _Future<T>.immediateError(error, stackTrace); |
| 201 } | 205 } |
| 202 | 206 |
| 203 /** | 207 /** |
| 204 * Creates a future that runs its computation after a delay. | 208 * Creates a future that runs its computation after a delay. |
| 205 * | 209 * |
| 206 * The [computation] will be executed after the given [duration] has passed, | 210 * 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 /** | 660 /** |
| 657 * Whether the future has been completed. | 661 * Whether the future has been completed. |
| 658 */ | 662 */ |
| 659 bool get isCompleted; | 663 bool get isCompleted; |
| 660 } | 664 } |
| 661 | 665 |
| 662 // Helper function completing a _Future with error, but checking the zone | 666 // Helper function completing a _Future with error, but checking the zone |
| 663 // for error replacement first. | 667 // for error replacement first. |
| 664 void _completeWithErrorCallback(_Future result, error, stackTrace) { | 668 void _completeWithErrorCallback(_Future result, error, stackTrace) { |
| 665 AsyncError replacement = Zone.current.errorCallback(error, stackTrace); | 669 AsyncError replacement = Zone.current.errorCallback(error, stackTrace); |
| 666 if (replacement == null) { | 670 if (replacement != null) { |
| 667 result._completeError(error, stackTrace); | 671 error = replacement.error; |
| 668 } else { | 672 if (error == null) error = new NullThrownError(); |
| 669 result._completeError(replacement.error, replacement.stackTrace); | 673 stackTrace = replacement.stackTrace; |
| 670 } | 674 } |
| 675 result._completeError(error, stackTrace); | |
| 671 } | 676 } |
| 672 | 677 |
| OLD | NEW |