Chromium Code Reviews| Index: corelib/src/future.dart |
| =================================================================== |
| --- corelib/src/future.dart (revision 3022) |
| +++ corelib/src/future.dart (working copy) |
| @@ -132,16 +132,27 @@ |
| // As each future completes, put its value into the corresponding |
| // position in the list of values. |
| for (int i = 0; i < futures.length; i++) { |
| - // TODO(mattsh) - remove this after bug |
| - // http://code.google.com/p/dart/issues/detail?id=333 is fixed. |
| - int pos = i; |
| - futures[pos].then((Object value) { |
| - values[pos] = value; |
| - if (--remaining == 0) { |
| - completer.complete(values); |
| - } |
| - }); |
| + if (futures[i].isComplete) { |
|
Siggi Cherem (dart-lang)
2012/01/10 18:56:43
(sorry for the slow reply I was OOO until today)
Anders Johnsen
2012/01/10 19:21:39
I was having problems with futures being complete
|
| + values[i] = futures[i].value; |
| + remaining--; |
| + } else { |
| + // TODO(mattsh) - remove this after bug |
| + // http://code.google.com/p/dart/issues/detail?id=333 is fixed. |
| + int pos = i; |
| + 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; |
| } |
| } |