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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/corelib/src/FuturesTest.dart » ('j') | tests/corelib/src/FuturesTest.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 * be a list of all the values that were produced.) 125 * be a list of all the values that were produced.)
126 */ 126 */
127 static Future<List> wait(List<Future> futures) { 127 static Future<List> wait(List<Future> futures) {
128 Completer completer = new Completer<List>(); 128 Completer completer = new Completer<List>();
129 int remaining = futures.length; 129 int remaining = futures.length;
130 List<Object> values = new List(futures.length); 130 List<Object> values = new List(futures.length);
131 131
132 // As each future completes, put its value into the corresponding 132 // As each future completes, put its value into the corresponding
133 // position in the list of values. 133 // position in the list of values.
134 for (int i = 0; i < futures.length; i++) { 134 for (int i = 0; i < futures.length; i++) {
135 // TODO(mattsh) - remove this after bug 135 if (futures[i].isComplete) {
136 // http://code.google.com/p/dart/issues/detail?id=333 is fixed. 136 values[i] = futures[i].value;
137 int pos = i; 137 remaining--;
138 futures[pos].then((Object value) { 138 } else {
139 values[pos] = value; 139 // TODO(mattsh) - remove this after bug
140 if (--remaining == 0) { 140 // http://code.google.com/p/dart/issues/detail?id=333 is fixed.
141 completer.complete(values); 141 int pos = i;
142 } 142 futures[pos].then((Object value) {
143 }); 143 values[pos] = value;
144 if (--remaining == 0) {
145 completer.complete(values);
146 }
147 });
148 }
144 } 149 }
150 // Special case where all the futures are already completed,
151 // trigger the value now.
152 if (remaining == 0) {
153 completer.complete(values);
154 }
155
145 return completer.future; 156 return completer.future;
146 } 157 }
147 } 158 }
148 159
OLDNEW
« no previous file with comments | « no previous file | tests/corelib/src/FuturesTest.dart » ('j') | tests/corelib/src/FuturesTest.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698