| 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 /** Test used by [Future.catchError] to handle skip some errors. */ | 9 /** Test used by [Future.catchError] to handle skip some errors. */ |
| 10 typedef bool _FutureErrorTest(var error); | 10 typedef bool _FutureErrorTest(var error); |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 } | 507 } |
| 508 listenerHasValue = false; | 508 listenerHasValue = false; |
| 509 } | 509 } |
| 510 }); | 510 }); |
| 511 if (isPropagationAborted) return; | 511 if (isPropagationAborted) return; |
| 512 // If the listener's value is a future we need to chain it. | 512 // If the listener's value is a future we need to chain it. |
| 513 if (listenerHasValue && listenerValueOrError is Future) { | 513 if (listenerHasValue && listenerValueOrError is Future) { |
| 514 Future chainSource = listenerValueOrError; | 514 Future chainSource = listenerValueOrError; |
| 515 // Shortcut if the chain-source is already completed. Just continue the | 515 // Shortcut if the chain-source is already completed. Just continue the |
| 516 // loop. | 516 // loop. |
| 517 if (chainSource is _Future && (chainSource as _Future)._isComplete) { | 517 if (chainSource is _Future && chainSource._isComplete) { |
| 518 // propagate the value (simulating a tail call). | 518 // propagate the value (simulating a tail call). |
| 519 listener._isChained = true; | 519 listener._isChained = true; |
| 520 source = chainSource; | 520 source = chainSource; |
| 521 listeners = listener; | 521 listeners = listener; |
| 522 continue; | 522 continue; |
| 523 } | 523 } |
| 524 _chainFutures(chainSource, listener); | 524 _chainFutures(chainSource, listener); |
| 525 return; | 525 return; |
| 526 } | 526 } |
| 527 | 527 |
| 528 if (listenerHasValue) { | 528 if (listenerHasValue) { |
| 529 listeners = listener._removeListeners(); | 529 listeners = listener._removeListeners(); |
| 530 listener._setValue(listenerValueOrError); | 530 listener._setValue(listenerValueOrError); |
| 531 } else { | 531 } else { |
| 532 listeners = listener._removeListeners(); | 532 listeners = listener._removeListeners(); |
| 533 _AsyncError asyncError = listenerValueOrError; | 533 _AsyncError asyncError = listenerValueOrError; |
| 534 listener._setError(asyncError.error, asyncError.stackTrace); | 534 listener._setError(asyncError.error, asyncError.stackTrace); |
| 535 } | 535 } |
| 536 // Prepare for next round. | 536 // Prepare for next round. |
| 537 source = listener; | 537 source = listener; |
| 538 } | 538 } |
| 539 } | 539 } |
| 540 } | 540 } |
| OLD | NEW |