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 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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. |
| 524 * The result of the [onTimeout] function must return a [T] or a `Future<T>`. | |
|
Lasse Reichstein Nielsen
2016/02/09 16:37:05
either "the [onTimeout] function must return"
or "
floitsch
2016/02/09 17:04:21
Done.
| |
| 524 * | 525 * |
| 525 * If `onTimeout` is omitted, a timeout will cause the returned future to | 526 * If `onTimeout` is omitted, a timeout will cause the returned future to |
| 526 * complete with a [TimeoutException]. | 527 * complete with a [TimeoutException]. |
| 527 */ | 528 */ |
| 528 Future timeout(Duration timeLimit, {onTimeout()}); | 529 Future<T> timeout(Duration timeLimit, {onTimeout()}); |
| 529 } | 530 } |
| 530 | 531 |
| 531 /** | 532 /** |
| 532 * Thrown when a scheduled timeout happens while waiting for an async result. | 533 * Thrown when a scheduled timeout happens while waiting for an async result. |
| 533 */ | 534 */ |
| 534 class TimeoutException implements Exception { | 535 class TimeoutException implements Exception { |
| 535 /** Description of the cause of the timeout. */ | 536 /** Description of the cause of the timeout. */ |
| 536 final String message; | 537 final String message; |
| 537 /** The duration that was exceeded. */ | 538 /** The duration that was exceeded. */ |
| 538 final Duration duration; | 539 final Duration duration; |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 720 if (replacement != null) { | 721 if (replacement != null) { |
| 721 error = _nonNullError(replacement.error); | 722 error = _nonNullError(replacement.error); |
| 722 stackTrace = replacement.stackTrace; | 723 stackTrace = replacement.stackTrace; |
| 723 } | 724 } |
| 724 result._completeError(error, stackTrace); | 725 result._completeError(error, stackTrace); |
| 725 } | 726 } |
| 726 | 727 |
| 727 /** Helper function that converts `null` to a [NullThrownError]. */ | 728 /** Helper function that converts `null` to a [NullThrownError]. */ |
| 728 Object _nonNullError(Object error) => | 729 Object _nonNullError(Object error) => |
| 729 (error != null) ? error : new NullThrownError(); | 730 (error != null) ? error : new NullThrownError(); |
| OLD | NEW |