| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of dart.async; | 5 part of dart.async; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * An object representing a delayed computation. | 8 * An object representing a delayed computation. |
| 9 * | 9 * |
| 10 * A [Future] is used to obtain a not yet | 10 * A [Future] is used to obtain a not yet |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 * complete. If any of the futures in the list completes with an error, | 211 * complete. If any of the futures in the list completes with an error, |
| 212 * the resulting future also completes with an error. Otherwise the value | 212 * the resulting future also completes with an error. Otherwise the value |
| 213 * of the returned future will be a list of all the values that were produced. | 213 * of the returned future will be a list of all the values that were produced. |
| 214 */ | 214 */ |
| 215 static Future<List> wait(Iterable<Future> futures) { | 215 static Future<List> wait(Iterable<Future> futures) { |
| 216 Completer completer; | 216 Completer completer; |
| 217 // List collecting values from the futures. | 217 // List collecting values from the futures. |
| 218 // Set to null if an error occurs. | 218 // Set to null if an error occurs. |
| 219 List values; | 219 List values; |
| 220 | 220 |
| 221 dynamic handleError(error) { | 221 dynamic handleError(error, stackTrace) { |
| 222 if (values != null) { | 222 if (values != null) { |
| 223 values = null; | 223 values = null; |
| 224 completer.completeError(error); | 224 completer.completeError(error, stackTrace); |
| 225 } | 225 } |
| 226 return null; | 226 return null; |
| 227 } | 227 } |
| 228 | 228 |
| 229 // As each future completes, put its value into the corresponding | 229 // As each future completes, put its value into the corresponding |
| 230 // position in the list of values. | 230 // position in the list of values. |
| 231 int remaining = 0; | 231 int remaining = 0; |
| 232 for (Future future in futures) { | 232 for (Future future in futures) { |
| 233 int pos = remaining++; | 233 int pos = remaining++; |
| 234 future.catchError(handleError).then((Object value) { | 234 future.catchError(handleError).then((Object value) { |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 * theFuture.catchError(thisCompleter.completeError); | 517 * theFuture.catchError(thisCompleter.completeError); |
| 518 * | 518 * |
| 519 */ | 519 */ |
| 520 void completeError(Object error, [StackTrace stackTrace]); | 520 void completeError(Object error, [StackTrace stackTrace]); |
| 521 | 521 |
| 522 /** | 522 /** |
| 523 * Whether the future has been completed. | 523 * Whether the future has been completed. |
| 524 */ | 524 */ |
| 525 bool get isCompleted; | 525 bool get isCompleted; |
| 526 } | 526 } |
| OLD | NEW |