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 represent a potential value, or error, | 10 * A [Future] is used to represent a potential value, or error, |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 * complete before the returned future is completed (still with the first | 247 * complete before the returned future is completed (still with the first |
248 * error to occur, the remaining errors are silently dropped). | 248 * error to occur, the remaining errors are silently dropped). |
249 * | 249 * |
250 * If [cleanUp] is provided, in the case of an error, any non-null result of | 250 * If [cleanUp] is provided, in the case of an error, any non-null result of |
251 * a successful future is passed to `cleanUp`, which can then release any | 251 * a successful future is passed to `cleanUp`, which can then release any |
252 * resources that the successful operation allocated. | 252 * resources that the successful operation allocated. |
253 * | 253 * |
254 * The call to `cleanUp` should not throw. If it does, the error will be an | 254 * The call to `cleanUp` should not throw. If it does, the error will be an |
255 * uncaught asynchronous error. | 255 * uncaught asynchronous error. |
256 */ | 256 */ |
257 static Future<List> wait(Iterable<Future> futures, | 257 static Future<List/*<T>*/> wait/*<T>*/(Iterable<Future/*<T>*/> futures, |
258 {bool eagerError: false, | 258 {bool eagerError: false, |
259 void cleanUp(successValue)}) { | 259 void cleanUp(/*=T*/ successValue)}) { |
Lasse Reichstein Nielsen
2015/11/19 06:58:32
The "=" is untraditional, but the rest is how we h
Jennifer Messerly
2015/11/20 17:41:18
Yeah, exactly, it's a lexical pattern to make it e
| |
260 final _Future<List> result = new _Future<List>(); | 260 final _Future<List> result = new _Future<List>(); |
261 List values; // Collects the values. Set to null on error. | 261 List values; // Collects the values. Set to null on error. |
262 int remaining = 0; // How many futures are we waiting for. | 262 int remaining = 0; // How many futures are we waiting for. |
263 var error; // The first error from a future. | 263 var error; // The first error from a future. |
264 StackTrace stackTrace; // The stackTrace that came with the error. | 264 StackTrace stackTrace; // The stackTrace that came with the error. |
265 | 265 |
266 // Handle an error from any of the futures. | 266 // Handle an error from any of the futures. |
267 void handleError(theError, theStackTrace) { | 267 void handleError(theError, theStackTrace) { |
268 remaining--; | 268 remaining--; |
269 if (values != null) { | 269 if (values != null) { |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
400 * the future returned by `then` will be completed with | 400 * the future returned by `then` will be completed with |
401 * the same result as the future returned by the callback. | 401 * the same result as the future returned by the callback. |
402 * | 402 * |
403 * If [onError] is not given, and this future completes with an error, | 403 * If [onError] is not given, and this future completes with an error, |
404 * the error is forwarded directly to the returned future. | 404 * the error is forwarded directly to the returned future. |
405 * | 405 * |
406 * In most cases, it is more readable to use [catchError] separately, possibly | 406 * In most cases, it is more readable to use [catchError] separately, possibly |
407 * with a `test` parameter, instead of handling both value and error in a | 407 * with a `test` parameter, instead of handling both value and error in a |
408 * single [then] call. | 408 * single [then] call. |
409 */ | 409 */ |
410 Future then(onValue(T value), { Function onError }); | 410 Future/*<S>*/ then/*<S>*/(/*=S*/ onValue(T value), { Function onError }); |
411 | 411 |
412 /** | 412 /** |
413 * Handles errors emitted by this [Future]. | 413 * Handles errors emitted by this [Future]. |
414 * | 414 * |
415 * This is the asynchronous equivalent of a "catch" block. | 415 * This is the asynchronous equivalent of a "catch" block. |
416 * | 416 * |
417 * Returns a new [Future] that will be completed with either the result of | 417 * Returns a new [Future] that will be completed with either the result of |
418 * this future or the result of calling the `onError` callback. | 418 * this future or the result of calling the `onError` callback. |
419 * | 419 * |
420 * If this future completes with a value, | 420 * If this future completes with a value, |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
720 if (replacement != null) { | 720 if (replacement != null) { |
721 error = _nonNullError(replacement.error); | 721 error = _nonNullError(replacement.error); |
722 stackTrace = replacement.stackTrace; | 722 stackTrace = replacement.stackTrace; |
723 } | 723 } |
724 result._completeError(error, stackTrace); | 724 result._completeError(error, stackTrace); |
725 } | 725 } |
726 | 726 |
727 /** Helper function that converts `null` to a [NullThrownError]. */ | 727 /** Helper function that converts `null` to a [NullThrownError]. */ |
728 Object _nonNullError(Object error) => | 728 Object _nonNullError(Object error) => |
729 (error != null) ? error : new NullThrownError(); | 729 (error != null) ? error : new NullThrownError(); |
OLD | NEW |