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

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: Allow transformException to complete successfully. 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
« no previous file with comments | « lib/core/future.dart ('k') | tests/corelib/future_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/coreimpl/future_implementation.dart
diff --git a/lib/coreimpl/future_implementation.dart b/lib/coreimpl/future_implementation.dart
index 328c88964c6be89f44914b7bdddb32a12102758e..0272fb68fc47e447db303218b8c0a5cfa0e623ea 100644
--- a/lib/coreimpl/future_implementation.dart
+++ b/lib/coreimpl/future_implementation.dart
@@ -171,20 +171,23 @@ class FutureImpl<T> implements Future<T> {
Future transform(Function transformation) {
final completer = new Completer();
+
handleException((e) {
- completer.completeException(e, this.stackTrace);
+ completer.completeException(e, stackTrace);
return true;
});
+
then((v) {
var transformed = null;
try {
transformed = transformation(v);
- } catch (ex, stackTrace) {
- completer.completeException(ex, stackTrace);
+ } catch (e, stackTrace) {
+ completer.completeException(e, stackTrace);
return;
}
completer.complete(transformed);
});
+
return completer.future;
}
@@ -210,6 +213,23 @@ class FutureImpl<T> implements Future<T> {
});
return completer.future;
}
+
+ Future transformException(transformation(Object exception)) {
+ final completer = new Completer();
+
+ handleException((ex) {
+ try {
+ completer.complete(transformation(ex));
+ } catch (innerException, stackTrace) {
+ completer.completeException(innerException, stackTrace);
+ }
+ return true;
+ });
+
+ then(completer.complete);
+
+ return completer.future;
+ }
}
class CompleterImpl<T> implements Completer<T> {
« 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