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

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

Issue 12317139: Make sure Future.forEach properly pipes exceptions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/lib/async/futures_test.dart » ('j') | 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 /** 7 /**
8 * A [Future] represents a delayed computation. It is used to obtain a not-yet 8 * A [Future] represents a delayed computation. It is used to obtain a not-yet
9 * available value, or error, sometime in the future. Receivers of a 9 * available value, or error, sometime in the future. Receivers of a
10 * [Future] can register callbacks that handle the value or error once it is 10 * [Future] can register callbacks that handle the value or error once it is
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 * completes when all elements have been processed. 183 * completes when all elements have been processed.
184 * 184 *
185 * The return values of all [Future]s are discarded. Any errors will cause the 185 * The return values of all [Future]s are discarded. Any errors will cause the
186 * iteration to stop and will be piped through the returned [Future]. 186 * iteration to stop and will be piped through the returned [Future].
187 */ 187 */
188 static Future forEach(Iterable input, Future f(element)) { 188 static Future forEach(Iterable input, Future f(element)) {
189 _FutureImpl doneSignal = new _FutureImpl(); 189 _FutureImpl doneSignal = new _FutureImpl();
190 Iterator iterator = input.iterator; 190 Iterator iterator = input.iterator;
191 void nextElement(_) { 191 void nextElement(_) {
192 if (iterator.moveNext()) { 192 if (iterator.moveNext()) {
193 f(iterator.current).then(nextElement, onError: doneSignal._setError); 193 new Future.of(() => f(iterator.current))
194 .then(nextElement, onError: doneSignal._setError);
194 } else { 195 } else {
195 doneSignal._setValue(null); 196 doneSignal._setValue(null);
196 } 197 }
197 } 198 }
198 nextElement(null); 199 nextElement(null);
199 return doneSignal; 200 return doneSignal;
200 } 201 }
201 202
202 /** 203 /**
203 * When this future completes with a value, then [onValue] is called with this 204 * When this future completes with a value, then [onValue] is called with this
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 * The argument [exception] should not be `null`. 357 * The argument [exception] should not be `null`.
357 * 358 *
358 * If [exception] is an [AsyncError], it is used directly as the error 359 * If [exception] is an [AsyncError], it is used directly as the error
359 * message sent to the future's listeners, and [stackTrace] is ignored. 360 * message sent to the future's listeners, and [stackTrace] is ignored.
360 * 361 *
361 * Otherwise the [exception] and an optional [stackTrace] is combined into an 362 * Otherwise the [exception] and an optional [stackTrace] is combined into an
362 * [AsyncError] and sent to this future's listeners. 363 * [AsyncError] and sent to this future's listeners.
363 */ 364 */
364 void completeError(Object exception, [Object stackTrace]); 365 void completeError(Object exception, [Object stackTrace]);
365 } 366 }
OLDNEW
« no previous file with comments | « no previous file | tests/lib/async/futures_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698