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: |
11 * | 11 * |
12 * Future<int> future = getFutureFromSomewhere(); | 12 * Future<int> future = getFutureFromSomewhere(); |
13 * future.then((value) { | 13 * future.then((value) { |
14 * print("I received the number " + value); | 14 * print("I received the number $value"); |
15 * }); | 15 * }); |
16 */ | 16 */ |
17 interface Future<T> default FutureImpl<T> { | 17 interface Future<T> default FutureImpl<T> { |
18 | 18 |
19 /** A future whose value is immediately available. */ | 19 /** A future whose value is immediately available. */ |
20 Future.immediate(T value); | 20 Future.immediate(T value); |
21 | 21 |
22 /** The value provided. Throws an exception if [hasValue] is false. */ | 22 /** The value provided. Throws an exception if [hasValue] is false. */ |
23 T get value(); | 23 T get value(); |
24 | 24 |
(...skipping 158 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 |