| 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 /// 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 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 * are discarded. | 444 * are discarded. |
| 445 * | 445 * |
| 446 * Any error from [f], synchronous or asynchronous, will stop the iteration | 446 * Any error from [f], synchronous or asynchronous, will stop the iteration |
| 447 * and will be reported in the returned [Future]. | 447 * and will be reported in the returned [Future]. |
| 448 */ | 448 */ |
| 449 static Future forEach<T>(Iterable<T> input, FutureOr f(T element)) { | 449 static Future forEach<T>(Iterable<T> input, FutureOr f(T element)) { |
| 450 var iterator = input.iterator; | 450 var iterator = input.iterator; |
| 451 return doWhile(() { | 451 return doWhile(() { |
| 452 if (!iterator.moveNext()) return false; | 452 if (!iterator.moveNext()) return false; |
| 453 var result = f(iterator.current); | 453 var result = f(iterator.current); |
| 454 if (result is Future<T>) return result.then(_kTrue); | 454 if (result is Future) return result.then(_kTrue); |
| 455 return true; | 455 return true; |
| 456 }); | 456 }); |
| 457 } | 457 } |
| 458 | 458 |
| 459 // Constant `true` function, used as callback by [forEach]. | 459 // Constant `true` function, used as callback by [forEach]. |
| 460 static bool _kTrue(_) => true; | 460 static bool _kTrue(_) => true; |
| 461 | 461 |
| 462 /** | 462 /** |
| 463 * Performs an operation repeatedly until it returns `false`. | 463 * Performs an operation repeatedly until it returns `false`. |
| 464 * | 464 * |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 AsyncError replacement = Zone.current.errorCallback(error, stackTrace); | 886 AsyncError replacement = Zone.current.errorCallback(error, stackTrace); |
| 887 if (replacement != null) { | 887 if (replacement != null) { |
| 888 error = _nonNullError(replacement.error); | 888 error = _nonNullError(replacement.error); |
| 889 stackTrace = replacement.stackTrace; | 889 stackTrace = replacement.stackTrace; |
| 890 } | 890 } |
| 891 result._asyncCompleteError(error, stackTrace); | 891 result._asyncCompleteError(error, stackTrace); |
| 892 } | 892 } |
| 893 | 893 |
| 894 /** Helper function that converts `null` to a [NullThrownError]. */ | 894 /** Helper function that converts `null` to a [NullThrownError]. */ |
| 895 Object _nonNullError(Object error) => error ?? new NullThrownError(); | 895 Object _nonNullError(Object error) => error ?? new NullThrownError(); |
| OLD | NEW |