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

Unified Diff: corelib/src/future.dart

Issue 8457005: convert isolates to use Future (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: updated co19 Created 9 years, 1 month 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 | « compiler/lib/implementation/isolate.dart ('k') | corelib/src/isolate.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: corelib/src/future.dart
diff --git a/corelib/src/future.dart b/corelib/src/future.dart
index 9842b8ef65c8fad727c1bed21fa266a25dff63a6..a044700b3f24359530492b7ab258c10defae1b1b 100644
--- a/corelib/src/future.dart
+++ b/corelib/src/future.dart
@@ -111,3 +111,38 @@ interface Completer<T> factory CompleterImpl<T> {
*/
void completeException(Object exception);
}
+
+
+/**
+ * This class is for utility functions that operate on Futures (for
+ * example, waiting for a collectin of Futures to complete).
+ */
+class Futures {
+
+ /**
+ * 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.)
+ */
+ static Future<List> wait(List<Future> futures) {
+ Completer completer = new Completer<List>();
+ int remaining = futures.length;
+ List<Object> values = new List(futures.length);
+
+ // 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);
+ }
+ });
+ }
+ return completer.future;
+ }
+}
+
« no previous file with comments | « compiler/lib/implementation/isolate.dart ('k') | corelib/src/isolate.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698