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

Side by Side Diff: lib/coreimpl/future_implementation.dart

Issue 10958021: If transformException() returns a future, act like chain(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 | « lib/core/future.dart ('k') | tests/corelib/future_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 2012 Google Inc. All Rights Reserved. 1 // Copyright 2012 Google Inc. All Rights Reserved.
2 // Dart core library. 2 // Dart core library.
3 3
4 class FutureImpl<T> implements Future<T> { 4 class FutureImpl<T> implements Future<T> {
5 5
6 bool _isComplete = false; 6 bool _isComplete = false;
7 7
8 /** 8 /**
9 * Value that was provided to this Future by the Completer 9 * Value that was provided to this Future by the Completer
10 */ 10 */
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 future.then((b) => completer.complete(b)); 212 future.then((b) => completer.complete(b));
213 }); 213 });
214 return completer.future; 214 return completer.future;
215 } 215 }
216 216
217 Future transformException(transformation(Object exception)) { 217 Future transformException(transformation(Object exception)) {
218 final completer = new Completer(); 218 final completer = new Completer();
219 219
220 handleException((ex) { 220 handleException((ex) {
221 try { 221 try {
222 completer.complete(transformation(ex)); 222 final result = transformation(ex);
223
224 // If the transformation itself returns a future, then we will
225 // complete to what that completes to.
226 if (result is Future) {
227 result.handleException((e) {
228 completer.completeException(e, result.stackTrace);
229 return true;
230 });
231 result.then((value) => completer.complete(value));
Siggi Cherem (dart-lang) 2012/09/20 22:00:17 I've seen the pattern of the last 4 lines quite a
Bob Nystrom 2012/09/20 22:34:53 Done. I put it in _FutureImpl (which, by the way,
232 } else {
233 completer.complete(result);
234 }
223 } catch (innerException, stackTrace) { 235 } catch (innerException, stackTrace) {
224 completer.completeException(innerException, stackTrace); 236 completer.completeException(innerException, stackTrace);
225 } 237 }
226 return true; 238 return true;
227 }); 239 });
228 240
229 then(completer.complete); 241 then(completer.complete);
230 242
231 return completer.future; 243 return completer.future;
232 } 244 }
(...skipping 10 matching lines...) Expand all
243 } 255 }
244 256
245 void complete(T value) { 257 void complete(T value) {
246 _futureImpl._setValue(value); 258 _futureImpl._setValue(value);
247 } 259 }
248 260
249 void completeException(Object exception, [Object stackTrace]) { 261 void completeException(Object exception, [Object stackTrace]) {
250 _futureImpl._setException(exception, stackTrace); 262 _futureImpl._setException(exception, stackTrace);
251 } 263 }
252 } 264 }
OLDNEW
« no previous file with comments | « lib/core/future.dart ('k') | tests/corelib/future_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698