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

Side by Side Diff: sdk/lib/async/future.dart

Issue 2824143002: Improve documentation for `Future.wait`. (Closed)
Patch Set: Add another sentence. Created 3 years, 8 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
« 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) 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 /// A type representing values that are either `Future<T>` or `T`. 7 /// A type representing values that are either `Future<T>` or `T`.
8 /// 8 ///
9 /// This class declaration is a public stand-in for an internal 9 /// This class declaration is a public stand-in for an internal
10 /// future-or-value generic type. References to this class are resolved to the 10 /// future-or-value generic type. References to this class are resolved to the
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 _completeWithErrorCallback(result, e, s); 283 _completeWithErrorCallback(result, e, s);
284 } 284 }
285 }); 285 });
286 return result; 286 return result;
287 } 287 }
288 288
289 /** 289 /**
290 * Wait for all the given futures to complete and collect their values. 290 * Wait for all the given futures to complete and collect their values.
291 * 291 *
292 * Returns a future which will complete once all the futures in a list are 292 * Returns a future which will complete once all the futures in a list are
293 * complete. If any of the futures in the list completes with an error, 293 * complete.
Lasse Reichstein Nielsen 2017/04/26 08:28:46 Maybe: are complete -> have completed (I think we
floitsch 2017/04/26 15:33:49 Done.
294 * the resulting future also completes with an error. Otherwise the value 294 *
295 * of the returned future will be a list of all the values that were 295 * The value of the returned future will be a list of all the values that
296 * produced. 296 * were produced.
297 *
298 * If any of given futures completes with an error, then the returned future
299 * completes with the first seen error instead.
Lasse Reichstein Nielsen 2017/04/26 08:28:46 first seen error -> first error seen (I think)
floitsch 2017/04/26 15:33:49 Reworded with the help of Seth.
297 * 300 *
298 * If `eagerError` is true, the future completes with an error immediately on 301 * If `eagerError` is true, the future completes with an error immediately on
299 * the first error from one of the futures. Otherwise all futures must 302 * the first error from one of the futures. Otherwise all futures must
300 * complete before the returned future is completed (still with the first 303 * complete before the returned future is completed (still with the first
301 * error to occur, the remaining errors are silently dropped). 304 * error to occur, the remaining errors are silently dropped).
302 * 305 *
303 * If [cleanUp] is provided, in the case of an error, any non-null result of 306 * In the case of an error, [cleanUp] (if provided), is invoked on any
304 * a successful future is passed to `cleanUp`, which can then release any 307 * non-null result of successful futures.
305 * resources that the successful operation allocated. 308 * This makes it posible to `cleanUp` resources that would otherwise be
309 * lost (since the returned future does not provide access to these values).
310 * The [cleanup] function is unused if there is no error.
306 * 311 *
307 * The call to `cleanUp` should not throw. If it does, the error will be an 312 * The call to `cleanUp` should not throw. If it does, the error will be an
308 * uncaught asynchronous error. 313 * uncaught asynchronous error.
309 */ 314 */
310 static Future<List<T>> wait<T>(Iterable<Future<T>> futures, 315 static Future<List<T>> wait<T>(Iterable<Future<T>> futures,
311 {bool eagerError: false, void cleanUp(T successValue)}) { 316 {bool eagerError: false, void cleanUp(T successValue)}) {
312 final _Future<List<T>> result = new _Future<List<T>>(); 317 final _Future<List<T>> result = new _Future<List<T>>();
313 List<T> values; // Collects the values. Set to null on error. 318 List<T> values; // Collects the values. Set to null on error.
314 int remaining = 0; // How many futures are we waiting for. 319 int remaining = 0; // How many futures are we waiting for.
315 var error; // The first error from a future. 320 var error; // The first error from a future.
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 AsyncError replacement = Zone.current.errorCallback(error, stackTrace); 846 AsyncError replacement = Zone.current.errorCallback(error, stackTrace);
842 if (replacement != null) { 847 if (replacement != null) {
843 error = _nonNullError(replacement.error); 848 error = _nonNullError(replacement.error);
844 stackTrace = replacement.stackTrace; 849 stackTrace = replacement.stackTrace;
845 } 850 }
846 result._completeError(error, stackTrace); 851 result._completeError(error, stackTrace);
847 } 852 }
848 853
849 /** Helper function that converts `null` to a [NullThrownError]. */ 854 /** Helper function that converts `null` to a [NullThrownError]. */
850 Object _nonNullError(Object error) => error ?? new NullThrownError(); 855 Object _nonNullError(Object error) => error ?? new NullThrownError();
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