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

Unified Diff: corelib/src/future.dart

Issue 9860010: If any of the futures passed to Futures.wait leads to (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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 | no next file » | 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 5856)
+++ corelib/src/future.dart (working copy)
@@ -159,11 +159,17 @@
/**
* 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.)
+ * complete. If any of the futures in the list completes with an exception,
+ * the resulting future also completes with an exception. (The value of the
+ * returned future will be a list of all the values that were produced.)
*/
static Future<List> wait(List<Future> futures) {
+ if (futures.isEmpty()) {
+ return new Future<List>.immediate(const []);
+ }
+
Completer completer = new Completer<List>();
+ Future<List> result = completer.future;
int remaining = futures.length;
List<Object> values = new List(futures.length);
@@ -173,20 +179,18 @@
// 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) {
+ Future future = futures[pos];
+ future.then((Object value) {
values[pos] = value;
- if (--remaining == 0) {
+ if (--remaining == 0 && !result.isComplete) {
completer.complete(values);
}
});
+ future.handleException((exception) {
+ if (!result.isComplete) completer.completeException(exception);
+ return true;
+ });
}
-
- // Special case where all the futures are already completed,
- // trigger the value now.
- if (futures.length == 0) {
- completer.complete(values);
- }
-
- return completer.future;
+ return result;
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698