Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Unified Diff: corelib/src/future.dart

Issue 9108010: Futures.wait should call then, even if some(or all) of the futures are done (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/corelib/src/FuturesTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
}
« no previous file with comments | « no previous file | tests/corelib/src/FuturesTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698