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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 * the future returned by `then` will be completed with | 490 * the future returned by `then` will be completed with |
491 * the same result as the future returned by the callback. | 491 * the same result as the future returned by the callback. |
492 * | 492 * |
493 * If [onError] is not given, and this future completes with an error, | 493 * If [onError] is not given, and this future completes with an error, |
494 * the error is forwarded directly to the returned future. | 494 * the error is forwarded directly to the returned future. |
495 * | 495 * |
496 * In most cases, it is more readable to use [catchError] separately, possibly | 496 * In most cases, it is more readable to use [catchError] separately, possibly |
497 * with a `test` parameter, instead of handling both value and error in a | 497 * with a `test` parameter, instead of handling both value and error in a |
498 * single [then] call. | 498 * single [then] call. |
499 */ | 499 */ |
500 Future<S> then<S>(onValue(T value), { Function onError }); | 500 Future<S> then<S>(FutureOr<S> onValue(T value), { Function onError }); |
501 | 501 |
502 /** | 502 /** |
503 * Handles errors emitted by this [Future]. | 503 * Handles errors emitted by this [Future]. |
504 * | 504 * |
505 * This is the asynchronous equivalent of a "catch" block. | 505 * This is the asynchronous equivalent of a "catch" block. |
506 * | 506 * |
507 * Returns a new [Future] that will be completed with either the result of | 507 * Returns a new [Future] that will be completed with either the result of |
508 * this future or the result of calling the `onError` callback. | 508 * this future or the result of calling the `onError` callback. |
509 * | 509 * |
510 * If this future completes with a value, | 510 * If this future completes with a value, |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 if (replacement != null) { | 820 if (replacement != null) { |
821 error = _nonNullError(replacement.error); | 821 error = _nonNullError(replacement.error); |
822 stackTrace = replacement.stackTrace; | 822 stackTrace = replacement.stackTrace; |
823 } | 823 } |
824 result._completeError(error, stackTrace); | 824 result._completeError(error, stackTrace); |
825 } | 825 } |
826 | 826 |
827 /** Helper function that converts `null` to a [NullThrownError]. */ | 827 /** Helper function that converts `null` to a [NullThrownError]. */ |
828 Object _nonNullError(Object error) => | 828 Object _nonNullError(Object error) => |
829 (error != null) ? error : new NullThrownError(); | 829 (error != null) ? error : new NullThrownError(); |
OLD | NEW |