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 /** The onValue and onError handlers return either a value or a future */ | 7 /** The onValue and onError handlers return either a value or a future */ |
| 8 typedef dynamic _FutureOnValue<T>(T value); | 8 typedef dynamic _FutureOnValue<T>(T value); |
| 9 typedef dynamic _FutureOnError(error); | 9 typedef dynamic _FutureOnError(error); |
| 10 /** Test used by [Future.catchError] to handle skip some errors. */ | 10 /** Test used by [Future.catchError] to handle skip some errors. */ |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 _FutureOnValue get _onValue => _isChained ? null : _onValueCallback; | 136 _FutureOnValue get _onValue => _isChained ? null : _onValueCallback; |
| 137 _FutureErrorTest get _errorTest => _isChained ? null : _errorTestCallback; | 137 _FutureErrorTest get _errorTest => _isChained ? null : _errorTestCallback; |
| 138 _FutureOnError get _onError => _isChained ? null : _onErrorCallback; | 138 _FutureOnError get _onError => _isChained ? null : _onErrorCallback; |
| 139 _FutureAction get _whenCompleteAction | 139 _FutureAction get _whenCompleteAction |
| 140 => _isChained ? null : _whenCompleteActionCallback; | 140 => _isChained ? null : _whenCompleteActionCallback; |
| 141 | 141 |
| 142 _Future() | 142 _Future() |
| 143 : _onValueCallback = null, _errorTestCallback = null, | 143 : _onValueCallback = null, _errorTestCallback = null, |
| 144 _onErrorCallback = null, _whenCompleteActionCallback = null; | 144 _onErrorCallback = null, _whenCompleteActionCallback = null; |
| 145 | 145 |
| 146 _Future.immediate(T value) | 146 // valid value types: T or Future<T> |
|
floitsch
2013/09/18 13:27:01
Start comment with capital character and finish wi
kevmoo-old
2013/09/18 13:41:52
Done.
| |
| 147 _Future.immediate(value) | |
| 147 : _onValueCallback = null, _errorTestCallback = null, | 148 : _onValueCallback = null, _errorTestCallback = null, |
| 148 _onErrorCallback = null, _whenCompleteActionCallback = null { | 149 _onErrorCallback = null, _whenCompleteActionCallback = null { |
| 149 _asyncComplete(value); | 150 _asyncComplete(value); |
| 150 } | 151 } |
| 151 | 152 |
| 152 _Future.immediateError(var error, [Object stackTrace]) | 153 _Future.immediateError(var error, [Object stackTrace]) |
| 153 : _onValueCallback = null, _errorTestCallback = null, | 154 : _onValueCallback = null, _errorTestCallback = null, |
| 154 _onErrorCallback = null, _whenCompleteActionCallback = null { | 155 _onErrorCallback = null, _whenCompleteActionCallback = null { |
| 155 _asyncCompleteError(error, stackTrace); | 156 _asyncCompleteError(error, stackTrace); |
| 156 } | 157 } |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 // Two corner cases if the value is a future: | 315 // Two corner cases if the value is a future: |
| 315 // 1. the future is already completed and an error. | 316 // 1. the future is already completed and an error. |
| 316 // 2. the future is not yet completed but might become an error. | 317 // 2. the future is not yet completed but might become an error. |
| 317 // The first case means that we must not immediately complete the Future, | 318 // The first case means that we must not immediately complete the Future, |
| 318 // as our code would immediately start propagating the error without | 319 // as our code would immediately start propagating the error without |
| 319 // giving the time to install error-handlers. | 320 // giving the time to install error-handlers. |
| 320 // However the second case requires us to deal with the value immediately. | 321 // However the second case requires us to deal with the value immediately. |
| 321 // Otherwise the value could complete with an error and report an | 322 // Otherwise the value could complete with an error and report an |
| 322 // unhandled error, even though we know we are already going to listen to | 323 // unhandled error, even though we know we are already going to listen to |
| 323 // it. | 324 // it. |
| 324 if (value is Future && | 325 if (value is Future && |
|
floitsch
2013/09/18 13:27:01
Maybe add (before this line):
// Assign to typed
kevmoo-old
2013/09/18 13:41:52
Done.
| |
| 325 (value is! _Future || !(value as _Future)._isComplete)) { | 326 (value is! _Future || !(value as _Future)._isComplete)) { |
| 326 // Case 2 from above. We need to register. | 327 // Case 2 from above. We need to register. |
| 327 // Note that we are still completing asynchronously: either we register | 328 // Note that we are still completing asynchronously: either we register |
| 328 // through .then (in which case the completing is asynchronous), or we | 329 // through .then (in which case the completing is asynchronous), or we |
| 329 // have a _Future which isn't complete yet. | 330 // have a _Future which isn't complete yet. |
| 330 _complete(value); | 331 _complete(value); |
| 331 return; | 332 return; |
| 332 } | 333 } |
| 333 | 334 |
| 334 _markPendingCompletion(); | 335 _markPendingCompletion(); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 506 listener._setValue(listenerValueOrError); | 507 listener._setValue(listenerValueOrError); |
| 507 } else { | 508 } else { |
| 508 listeners = listener._removeListeners(); | 509 listeners = listener._removeListeners(); |
| 509 listener._setError(listenerValueOrError); | 510 listener._setError(listenerValueOrError); |
| 510 } | 511 } |
| 511 // Prepare for next round. | 512 // Prepare for next round. |
| 512 source = listener; | 513 source = listener; |
| 513 } | 514 } |
| 514 } | 515 } |
| 515 } | 516 } |
| OLD | NEW |