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

Unified Diff: lib/coreimpl/future_implementation.dart

Issue 10908040: Support transforming the exception in Future.transform(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Split transformException() out into separate method. 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 side-by-side diff with in-line comments
Download patch
Index: lib/coreimpl/future_implementation.dart
diff --git a/lib/coreimpl/future_implementation.dart b/lib/coreimpl/future_implementation.dart
index 328c88964c6be89f44914b7bdddb32a12102758e..52453b1eea5eb0f125e4db3c0cd0dab7d0521360 100644
--- a/lib/coreimpl/future_implementation.dart
+++ b/lib/coreimpl/future_implementation.dart
@@ -171,10 +171,12 @@ class FutureImpl<T> implements Future<T> {
Future transform(Function transformation) {
final completer = new Completer();
- handleException((e) {
- completer.completeException(e, this.stackTrace);
+
+ handleException((ex) {
nweiz 2012/09/04 20:26:14 Why are you renaming this to "ex"? "catch (e)" is
Bob Nystrom 2012/09/04 21:14:43 Stale change. Removed.
+ completer.completeException(ex, stackTrace);
return true;
});
+
then((v) {
var transformed = null;
try {
@@ -185,6 +187,7 @@ class FutureImpl<T> implements Future<T> {
}
completer.complete(transformed);
});
+
return completer.future;
}
@@ -210,6 +213,31 @@ class FutureImpl<T> implements Future<T> {
});
return completer.future;
}
+
+ Future transformException(bool transformation(Object exception)) {
+ final completer = new Completer();
+
+ handleException((ex) {
+ var result = false;
+ var resultStackTrace = stackTrace;
+ try {
+ result = transformation(ex);
+ } catch (innerException, innerStackTrace) {
+ ex = innerException;
+ resultStackTrace = innerStackTrace;
+ }
+
+ if (result != true) {
+ completer.completeException(ex, resultStackTrace);
+ }
+
+ return true;
+ });
+
+ then(completer.complete);
+
+ return completer.future;
+ }
}
class CompleterImpl<T> implements Completer<T> {
« lib/core/future.dart ('K') | « 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