| 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] obtain the value by passing a callback to [then]. For example: | 10 * [Future] obtain the value by passing a callback to [then]. For example: |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 Completer(); | 123 Completer(); |
| 124 | 124 |
| 125 /** The future that will contain the value produced by this completer. */ | 125 /** The future that will contain the value produced by this completer. */ |
| 126 Future get future(); | 126 Future get future(); |
| 127 | 127 |
| 128 /** Supply a value for [future]. */ | 128 /** Supply a value for [future]. */ |
| 129 void complete(T value); | 129 void complete(T value); |
| 130 | 130 |
| 131 /** | 131 /** |
| 132 * Indicate in [future] that an exception occured while trying to produce its | 132 * Indicate in [future] that an exception occured while trying to produce its |
| 133 * value. The argument [exception] argument should not be [:null:]. | 133 * value. The argument [exception] should not be [:null:]. |
| 134 */ | 134 */ |
| 135 void completeException(Object exception); | 135 void completeException(Object exception); |
| 136 } | 136 } |
| 137 | 137 |
| 138 /** Thrown when reading a future's properties before it is complete. */ | 138 /** Thrown when reading a future's properties before it is complete. */ |
| 139 class FutureNotCompleteException implements Exception { | 139 class FutureNotCompleteException implements Exception { |
| 140 FutureNotCompleteException() {} | 140 FutureNotCompleteException() {} |
| 141 String toString() => "Exception: future has not been completed"; | 141 String toString() => "Exception: future has not been completed"; |
| 142 } | 142 } |
| 143 | 143 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 183 |
| 184 // Special case where all the futures are already completed, | 184 // Special case where all the futures are already completed, |
| 185 // trigger the value now. | 185 // trigger the value now. |
| 186 if (futures.length == 0) { | 186 if (futures.length == 0) { |
| 187 completer.complete(values); | 187 completer.complete(values); |
| 188 } | 188 } |
| 189 | 189 |
| 190 return completer.future; | 190 return completer.future; |
| 191 } | 191 } |
| 192 } | 192 } |
| OLD | NEW |