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

Side by Side 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: fixed TestFramework.dart 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // Dart core library. 5 // Dart core library.
6 6
7 7
8 /** 8 /**
9 * A Future is used to obtain a value sometime in the 9 * A Future is used to obtain a value sometime in the
10 * future. 10 * future.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 /** 104 /**
105 * Called when value is available. 105 * Called when value is available.
106 */ 106 */
107 void complete(T value); 107 void complete(T value);
108 108
109 /** 109 /**
110 * Called if an exception occured while trying to produce value. 110 * Called if an exception occured while trying to produce value.
111 */ 111 */
112 void completeException(Object exception); 112 void completeException(Object exception);
113 } 113 }
114
115
116 class Futures {
Siggi Cherem (dart-lang) 2011/11/04 16:57:33 + comment on this class
mattsh 2011/11/04 17:10:31 Done.
117
118 /**
119 * Returns a future which will complete once all the futures in a
120 * list are complete. (The value of the returned future will
121 * be a list of all the values that were produced.)
122 */
123 static Future<List> wait(List<Future> futures) {
124 Completer completer = new Completer<Object>();
Siggi Cherem (dart-lang) 2011/11/04 16:57:33 Compelter<Object> -> Completer<List>?
mattsh 2011/11/04 17:10:31 Done.
125 int remaining = futures.length;
126 List<Object> values = new List(futures.length);
Siggi Cherem (dart-lang) 2011/11/04 16:57:33 List<Object> -> List (let it be dynamic)
mattsh 2011/11/04 17:10:31 I think it should be List<Object> here because we
127
128 // As each future completes, put its value into the corresponding
129 // position in the list of values.
130 for (int i = 0; i < futures.length; i++) {
131 int pos = i;
Siggi Cherem (dart-lang) 2011/11/04 16:57:33 add here a TODO to remove this once loop-var captu
mattsh 2011/11/04 17:10:31 Done.
132 futures[pos].then((Object value) {
Siggi Cherem (dart-lang) 2011/11/04 16:57:33 Object -> var, or remove the type annotation.
mattsh 2011/11/04 17:10:31 See above.
133 values[pos] = value;
134 if (--remaining == 0) {
135 completer.complete(values);
136 }
137 });
138 }
139 return completer.future;
140 }
Siggi Cherem (dart-lang) 2011/11/04 16:57:33 to address Ben's concern, let's add here a method
mattsh 2011/11/04 17:10:31 Can do in follow up CL.
141 }
142
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698