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 * A [Future] is used to obtain a value sometime in the future. Receivers of a | 8 * A [Future] is used to obtain a value sometime in the future. Receivers of a |
9 * [Future] can obtain the value by passing a callback to [then]. For example: | 9 * [Future] can obtain the value by passing a callback to [then]. For example: |
10 * | 10 * |
11 * Future<int> future = getFutureFromSomewhere(); | 11 * Future<int> future = getFutureFromSomewhere(); |
12 * future.then((value) { | 12 * future.then((value) { |
13 * print("I received the number $value"); | 13 * print("I received the number $value"); |
14 * }); | 14 * }); |
15 * | 15 * |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 */ | 185 */ |
186 static Future forEach(Iterable input, Future f(element)) { | 186 static Future forEach(Iterable input, Future f(element)) { |
187 var iterator = input.iterator; | 187 var iterator = input.iterator; |
188 Future nextElement(_) { | 188 Future nextElement(_) { |
189 if (!iterator.moveNext()) return new Future.immediate(null); | 189 if (!iterator.moveNext()) return new Future.immediate(null); |
190 return f(iterator.current).then(nextElement); | 190 return f(iterator.current).then(nextElement); |
191 } | 191 } |
192 return nextElement(null); | 192 return nextElement(null); |
193 } | 193 } |
194 } | 194 } |
OLD | NEW |