| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // Dart core library. | 5 // Dart core library. |
| 6 | 6 |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * A [Future] is used to obtain a value sometime in the future. Receivers of a | 9 * A [Future] is used to obtain a value sometime in the future. Receivers of a |
| 10 * [Future] can obtain the value by passing a callback to [then]. | 10 * [Future] can obtain the value by passing a callback to [then]. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * | 21 * |
| 22 * When a future completes: | 22 * When a future completes: |
| 23 * | 23 * |
| 24 * 1. if the future suceeded, handlers registered with [then] are called. | 24 * 1. if the future suceeded, handlers registered with [then] are called. |
| 25 * 2. if the future failed, handlers registered with [handleException] are | 25 * 2. if the future failed, handlers registered with [handleException] are |
| 26 * called in sequence, until one returns true. | 26 * called in sequence, until one returns true. |
| 27 * 3. handlers registered with [onComplete] are called | 27 * 3. handlers registered with [onComplete] are called |
| 28 * 4. if the future failed, and at least one handler was registered with | 28 * 4. if the future failed, and at least one handler was registered with |
| 29 * [then], and no handler registered with [handleException] returned | 29 * [then], and no handler registered with [handleException] returned |
| 30 * [:true:], then the exception is thrown. | 30 * [:true:], then the exception is thrown. |
| 31 * |
| 32 * Use a [Completer] to create and change the state of a [Future]. |
| 31 */ | 33 */ |
| 32 interface Future<T> default FutureImpl<T> { | 34 interface Future<T> default FutureImpl<T> { |
| 33 | 35 |
| 34 /** A future whose value is immediately available. */ | 36 /** A future whose value is immediately available. */ |
| 35 Future.immediate(T value); | 37 Future.immediate(T value); |
| 36 | 38 |
| 37 /** The value provided. Throws an exception if [hasValue] is false. */ | 39 /** The value provided. Throws an exception if [hasValue] is false. */ |
| 38 T get value(); | 40 T get value(); |
| 39 | 41 |
| 40 /** | 42 /** |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 } | 205 } |
| 204 }); | 206 }); |
| 205 future.handleException((exception) { | 207 future.handleException((exception) { |
| 206 if (!result.isComplete) completer.completeException(exception); | 208 if (!result.isComplete) completer.completeException(exception); |
| 207 return true; | 209 return true; |
| 208 }); | 210 }); |
| 209 } | 211 } |
| 210 return result; | 212 return result; |
| 211 } | 213 } |
| 212 } | 214 } |
| OLD | NEW |