Chromium Code Reviews| Index: corelib/src/future.dart |
| =================================================================== |
| --- corelib/src/future.dart (revision 2994) |
| +++ corelib/src/future.dart (working copy) |
| @@ -135,13 +135,24 @@ |
| // TODO(mattsh) - remove this after bug |
| // http://code.google.com/p/dart/issues/detail?id=333 is fixed. |
| int pos = i; |
|
kasperl
2012/01/06 08:17:53
Maybe move the declaration of pos (and the TODO) d
Anders Johnsen
2012/01/06 08:57:09
Done.
|
| - futures[pos].then((Object value) { |
| - values[pos] = value; |
| - if (--remaining == 0) { |
| - completer.complete(values); |
| - } |
| - }); |
| + if (futures[pos].isComplete) { |
| + remaining--; |
|
kasperl
2012/01/06 08:17:53
Nit: Maybe update remaining after storing the valu
Anders Johnsen
2012/01/06 08:57:09
Done.
|
| + values[pos] = futures[pos].value; |
| + } else { |
| + futures[pos].then((Object value) { |
| + values[pos] = value; |
| + if (--remaining == 0) { |
| + completer.complete(values); |
| + } |
| + }); |
| + } |
| } |
| + // Special case where all the futures are already completed, |
| + // trigger the value now. |
| + if (remaining == 0) { |
| + completer.complete(values); |
| + } |
| + |
| return completer.future; |
| } |
| } |