| 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) {
|
| + 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;
|
| }
|
| }
|
|
|