| 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 obtain a not yet | 10 * A [Future] is used to obtain a not yet |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 * If `onTimeout` is omitted, a timeout will cause the returned future to | 422 * If `onTimeout` is omitted, a timeout will cause the returned future to |
| 423 * complete with a [TimeoutException]. | 423 * complete with a [TimeoutException]. |
| 424 */ | 424 */ |
| 425 Future timeout(Duration timeLimit, {void onTimeout()}); | 425 Future timeout(Duration timeLimit, {void onTimeout()}); |
| 426 } | 426 } |
| 427 | 427 |
| 428 /** | 428 /** |
| 429 * Thrown when a scheduled timeout happens while waiting for an async result. | 429 * Thrown when a scheduled timeout happens while waiting for an async result. |
| 430 */ | 430 */ |
| 431 class TimeoutException implements Exception { | 431 class TimeoutException implements Exception { |
| 432 /** The duration that was exceeded without a result. */ | 432 /** Description of the cause of the timeout. */ |
| 433 final String message; |
| 434 /** The duration that was exceeded. */ |
| 433 final Duration duration; | 435 final Duration duration; |
| 434 | 436 |
| 435 TimeoutException(this.duration); | 437 TimeoutException(this.message, [this.duration]); |
| 436 | 438 |
| 437 String toString() => "Timeout after $duration"; | 439 String toString() { |
| 440 if (message != null) { |
| 441 if (duration != null) return "TimeoutException after $duration: $message"; |
| 442 return "TimeoutException: $message"; |
| 443 } |
| 444 if (duration != null) return "TimeoutException after $duration"; |
| 445 return "TimeoutException"; |
| 446 } |
| 438 } | 447 } |
| 439 | 448 |
| 440 /** | 449 /** |
| 441 * A way to produce Future objects and to complete them later | 450 * A way to produce Future objects and to complete them later |
| 442 * with a value or error. | 451 * with a value or error. |
| 443 * | 452 * |
| 444 * If you already have a Future, you probably don't need a Completer. | 453 * If you already have a Future, you probably don't need a Completer. |
| 445 * Instead, you can usually use [Future.then], which returns a Future: | 454 * Instead, you can usually use [Future.then], which returns a Future: |
| 446 * | 455 * |
| 447 * Future doStuff(){ | 456 * Future doStuff(){ |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 * theFuture.catchError(thisCompleter.completeError); | 570 * theFuture.catchError(thisCompleter.completeError); |
| 562 * | 571 * |
| 563 */ | 572 */ |
| 564 void completeError(Object error, [StackTrace stackTrace]); | 573 void completeError(Object error, [StackTrace stackTrace]); |
| 565 | 574 |
| 566 /** | 575 /** |
| 567 * Whether the future has been completed. | 576 * Whether the future has been completed. |
| 568 */ | 577 */ |
| 569 bool get isCompleted; | 578 bool get isCompleted; |
| 570 } | 579 } |
| OLD | NEW |