| 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 /// A type representing values that are either `Future<T>` or `T`. | 7 /// A type representing values that are either `Future<T>` or `T`. |
| 8 /// | 8 /// |
| 9 /// This class declaration is a public stand-in for an internal | 9 /// This class declaration is a public stand-in for an internal |
| 10 /// future-or-value generic type. References to this class are resolved to the | 10 /// future-or-value generic type. References to this class are resolved to the |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 * if (onError is ZoneBinaryCallback) { | 546 * if (onError is ZoneBinaryCallback) { |
| 547 * return onError(e, stackTrace); | 547 * return onError(e, stackTrace); |
| 548 * } | 548 * } |
| 549 * return onError(e); | 549 * return onError(e); |
| 550 * } | 550 * } |
| 551 * throw e; | 551 * throw e; |
| 552 * }); | 552 * }); |
| 553 * } | 553 * } |
| 554 * | 554 * |
| 555 */ | 555 */ |
| 556 // The `Function` below can stand for several types: | 556 // The `Function` below stands for one of two types: |
| 557 // - (dynamic) -> T | 557 // - (dynamic) -> FutureOr<T> |
| 558 // - (dynamic, StackTrace) -> T | 558 // - (dynamic, StackTrace) -> FutureOr<T> |
| 559 // - (dynamic) -> Future<T> | |
| 560 // - (dynamic, StackTrace) -> Future<T> | |
| 561 // Given that there is a `test` function that is usually used to do an | 559 // Given that there is a `test` function that is usually used to do an |
| 562 // `isCheck` we should also expect functions that take a specific argument. | 560 // `isCheck` we should also expect functions that take a specific argument. |
| 563 // Note: making `catchError` return a `Future<T>` in non-strong mode could be | 561 // Note: making `catchError` return a `Future<T>` in non-strong mode could be |
| 564 // a breaking change. | 562 // a breaking change. |
| 565 Future<T> catchError(Function onError, | 563 Future<T> catchError(Function onError, |
| 566 {bool test(Object error)}); | 564 {bool test(Object error)}); |
| 567 | 565 |
| 568 /** | 566 /** |
| 569 * Register a function to be called when this future completes. | 567 * Register a function to be called when this future completes. |
| 570 * | 568 * |
| 571 * The [action] function is called when this future completes, whether it | 569 * The [action] function is called when this future completes, whether it |
| 572 * does so with a value or with an error. | 570 * does so with a value or with an error. |
| 573 * | 571 * |
| 574 * This is the asynchronous equivalent of a "finally" block. | 572 * This is the asynchronous equivalent of a "finally" block. |
| 575 * | 573 * |
| 576 * The future returned by this call, `f`, will complete the same way | 574 * The future returned by this call, `f`, will complete the same way |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 * or a future of type `Future<T>`. | 776 * or a future of type `Future<T>`. |
| 779 * | 777 * |
| 780 * If the value is itself a future, the completer will wait for that future | 778 * If the value is itself a future, the completer will wait for that future |
| 781 * to complete, and complete with the same result, whether it is a success | 779 * to complete, and complete with the same result, whether it is a success |
| 782 * or an error. | 780 * or an error. |
| 783 * | 781 * |
| 784 * Calling `complete` or [completeError] must not be done more than once. | 782 * Calling `complete` or [completeError] must not be done more than once. |
| 785 * | 783 * |
| 786 * All listeners on the future are informed about the value. | 784 * All listeners on the future are informed about the value. |
| 787 */ | 785 */ |
| 788 void complete([value]); | 786 void complete([FutureOr<T> value]); |
| 789 | 787 |
| 790 /** | 788 /** |
| 791 * Complete [future] with an error. | 789 * Complete [future] with an error. |
| 792 * | 790 * |
| 793 * Calling [complete] or `completeError` must not be done more than once. | 791 * Calling [complete] or `completeError` must not be done more than once. |
| 794 * | 792 * |
| 795 * Completing a future with an error indicates that an exception was thrown | 793 * Completing a future with an error indicates that an exception was thrown |
| 796 * while trying to produce a value. | 794 * while trying to produce a value. |
| 797 * | 795 * |
| 798 * If [error] is `null`, it is replaced by a [NullThrownError]. | 796 * If [error] is `null`, it is replaced by a [NullThrownError]. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 820 void _completeWithErrorCallback(_Future result, error, stackTrace) { | 818 void _completeWithErrorCallback(_Future result, error, stackTrace) { |
| 821 AsyncError replacement = Zone.current.errorCallback(error, stackTrace); | 819 AsyncError replacement = Zone.current.errorCallback(error, stackTrace); |
| 822 if (replacement != null) { | 820 if (replacement != null) { |
| 823 error = _nonNullError(replacement.error); | 821 error = _nonNullError(replacement.error); |
| 824 stackTrace = replacement.stackTrace; | 822 stackTrace = replacement.stackTrace; |
| 825 } | 823 } |
| 826 result._completeError(error, stackTrace); | 824 result._completeError(error, stackTrace); |
| 827 } | 825 } |
| 828 | 826 |
| 829 /** Helper function that converts `null` to a [NullThrownError]. */ | 827 /** Helper function that converts `null` to a [NullThrownError]. */ |
| 830 Object _nonNullError(Object error) => | 828 Object _nonNullError(Object error) => error ?? new NullThrownError(); |
| 831 (error != null) ? error : new NullThrownError(); | |
| OLD | NEW |