Chromium Code Reviews| Index: corelib/src/future.dart |
| diff --git a/corelib/src/future.dart b/corelib/src/future.dart |
| index 9842b8ef65c8fad727c1bed21fa266a25dff63a6..8c2eb18b2169e53cd72ca1c70fa7f19f748341bf 100644 |
| --- a/corelib/src/future.dart |
| +++ b/corelib/src/future.dart |
| @@ -111,3 +111,32 @@ interface Completer<T> factory CompleterImpl<T> { |
| */ |
| void completeException(Object exception); |
| } |
| + |
| + |
| +class Futures { |
|
Siggi Cherem (dart-lang)
2011/11/04 16:57:33
+ comment on this class
mattsh
2011/11/04 17:10:31
Done.
|
| + |
| + /** |
| + * Returns a future which will complete once all the futures in a |
| + * list are complete. (The value of the returned future will |
| + * be a list of all the values that were produced.) |
| + */ |
| + static Future<List> wait(List<Future> futures) { |
| + Completer completer = new Completer<Object>(); |
|
Siggi Cherem (dart-lang)
2011/11/04 16:57:33
Compelter<Object> -> Completer<List>?
mattsh
2011/11/04 17:10:31
Done.
|
| + int remaining = futures.length; |
| + List<Object> values = new List(futures.length); |
|
Siggi Cherem (dart-lang)
2011/11/04 16:57:33
List<Object> -> List (let it be dynamic)
mattsh
2011/11/04 17:10:31
I think it should be List<Object> here because we
|
| + |
| + // As each future completes, put its value into the corresponding |
| + // position in the list of values. |
| + for (int i = 0; i < futures.length; i++) { |
| + int pos = i; |
|
Siggi Cherem (dart-lang)
2011/11/04 16:57:33
add here a TODO to remove this once loop-var captu
mattsh
2011/11/04 17:10:31
Done.
|
| + futures[pos].then((Object value) { |
|
Siggi Cherem (dart-lang)
2011/11/04 16:57:33
Object -> var, or remove the type annotation.
mattsh
2011/11/04 17:10:31
See above.
|
| + values[pos] = value; |
| + if (--remaining == 0) { |
| + completer.complete(values); |
| + } |
| + }); |
| + } |
| + return completer.future; |
| + } |
|
Siggi Cherem (dart-lang)
2011/11/04 16:57:33
to address Ben's concern, let's add here a method
mattsh
2011/11/04 17:10:31
Can do in follow up CL.
|
| +} |
| + |