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

Side by Side Diff: corelib/src/future.dart

Issue 9166037: Remove redundant code from Futures.wait. (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 | no next file » | no next file with comments »
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 if (futures[i].isComplete) { 135 // TODO(mattsh) - remove this after bug
136 values[i] = futures[i].value; 136 // http://code.google.com/p/dart/issues/detail?id=333 is fixed.
137 remaining--; 137 int pos = i;
138 } else { 138 futures[pos].then((Object value) {
139 // TODO(mattsh) - remove this after bug 139 values[pos] = value;
140 // http://code.google.com/p/dart/issues/detail?id=333 is fixed. 140 if (--remaining == 0) {
141 int pos = i; 141 completer.complete(values);
142 futures[pos].then((Object value) { 142 }
143 values[pos] = value; 143 });
144 if (--remaining == 0) {
145 completer.complete(values);
146 }
147 });
148 }
149 } 144 }
150 // Special case where all the futures are already completed, 145 // Special case where all the futures are already completed,
151 // trigger the value now. 146 // trigger the value now.
152 if (remaining == 0) { 147 if (futures.length == 0) {
153 completer.complete(values); 148 completer.complete(values);
154 } 149 }
155 150
156 return completer.future; 151 return completer.future;
157 } 152 }
158 } 153 }
159 154
OLDNEW
« 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