Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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) { |
|
Siggi Cherem (dart-lang)
2012/01/10 18:56:43
(sorry for the slow reply I was OOO until today)
Anders Johnsen
2012/01/10 19:21:39
I was having problems with futures being complete
| |
| 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 |
| OLD | NEW |