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 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 513 Stream<T> asStream(); | 513 Stream<T> asStream(); |
| 514 | 514 |
| 515 /** | 515 /** |
| 516 * Time-out the future computation after [timeLimit] has passed. | 516 * Time-out the future computation after [timeLimit] has passed. |
| 517 * | 517 * |
| 518 * Returns a new future that completes with the same value as this future, | 518 * Returns a new future that completes with the same value as this future, |
| 519 * if this future completes in time. | 519 * if this future completes in time. |
| 520 * | 520 * |
| 521 * If this future does not complete before `timeLimit` has passed, | 521 * If this future does not complete before `timeLimit` has passed, |
| 522 * the [onTimeout] action is executed instead, and its result (whether it | 522 * the [onTimeout] action is executed instead, and its result (whether it |
| 523 * returns or throws) is used as the result of the returned future. | 523 * returns or throws) is used as the result of the returned future. |
|
Lasse Reichstein Nielsen
2015/08/14 22:08:35
Document that onTimeout must return T or Future<T>
floitsch
2016/02/09 16:30:26
I agree, but it seems very unlikely.
| |
| 524 * | 524 * |
| 525 * If `onTimeout` is omitted, a timeout will cause the returned future to | 525 * If `onTimeout` is omitted, a timeout will cause the returned future to |
| 526 * complete with a [TimeoutException]. | 526 * complete with a [TimeoutException]. |
| 527 */ | 527 */ |
| 528 Future timeout(Duration timeLimit, {onTimeout()}); | 528 Future<T> timeout(Duration timeLimit, {onTimeout()}); |
| 529 } | 529 } |
| 530 | 530 |
| 531 /** | 531 /** |
| 532 * Thrown when a scheduled timeout happens while waiting for an async result. | 532 * Thrown when a scheduled timeout happens while waiting for an async result. |
| 533 */ | 533 */ |
| 534 class TimeoutException implements Exception { | 534 class TimeoutException implements Exception { |
| 535 /** Description of the cause of the timeout. */ | 535 /** Description of the cause of the timeout. */ |
| 536 final String message; | 536 final String message; |
| 537 /** The duration that was exceeded. */ | 537 /** The duration that was exceeded. */ |
| 538 final Duration duration; | 538 final Duration duration; |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 720 if (replacement != null) { | 720 if (replacement != null) { |
| 721 error = _nonNullError(replacement.error); | 721 error = _nonNullError(replacement.error); |
| 722 stackTrace = replacement.stackTrace; | 722 stackTrace = replacement.stackTrace; |
| 723 } | 723 } |
| 724 result._completeError(error, stackTrace); | 724 result._completeError(error, stackTrace); |
| 725 } | 725 } |
| 726 | 726 |
| 727 /** Helper function that converts `null` to a [NullThrownError]. */ | 727 /** Helper function that converts `null` to a [NullThrownError]. */ |
| 728 Object _nonNullError(Object error) => | 728 Object _nonNullError(Object error) => |
| 729 (error != null) ? error : new NullThrownError(); | 729 (error != null) ? error : new NullThrownError(); |
| OLD | NEW |