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

Unified Diff: sdk/lib/core/future_impl.dart

Issue 11412139: Make exceptions propagate through multiple Future branches. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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 | « no previous file | tests/co19/co19-compiler.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/core/future_impl.dart
diff --git a/sdk/lib/core/future_impl.dart b/sdk/lib/core/future_impl.dart
index bbae82d1667ffaff49b056c537143ee23b10d050..2c22e46123115e6b3dd852f5ed4fc5333f1975c7 100644
--- a/sdk/lib/core/future_impl.dart
+++ b/sdk/lib/core/future_impl.dart
@@ -27,6 +27,11 @@ class _FutureImpl<T> implements Future<T> {
bool _exceptionHandled = false;
/**
+ * true if an exception in this future should be thrown to the top level.
+ */
+ bool _throwOnException = false;
+
+ /**
* Listeners waiting to receive the value of this future.
*/
final List<Function> _successListeners;
@@ -88,12 +93,21 @@ class _FutureImpl<T> implements Future<T> {
if (hasValue) {
onSuccess(value);
} else if (!isComplete) {
+ _throwOnException = true;
_successListeners.add(onSuccess);
} else if (!_exceptionHandled) {
throw new FutureUnhandledException(_exception, stackTrace);
}
}
+ void _handleSuccess(void onSuccess(T value)) {
+ if (hasValue) {
+ onSuccess(value);
+ } else if (!isComplete) {
+ _successListeners.add(onSuccess);
+ }
+ }
+
void handleException(bool onException(Object exception)) {
if (_exceptionHandled) return;
if (_isComplete) {
@@ -135,7 +149,7 @@ class _FutureImpl<T> implements Future<T> {
listener(value);
}
} else {
- if (!_exceptionHandled && _successListeners.length > 0) {
+ if (!_exceptionHandled && _throwOnException) {
throw new FutureUnhandledException(_exception, stackTrace);
}
}
@@ -174,7 +188,7 @@ class _FutureImpl<T> implements Future<T> {
_forwardException(this, completer);
- then((v) {
+ _handleSuccess((v) {
var transformed = null;
try {
transformed = transformation(v);
@@ -192,7 +206,7 @@ class _FutureImpl<T> implements Future<T> {
final completer = new Completer();
_forwardException(this, completer);
- then((v) {
+ _handleSuccess((v) {
var future = null;
try {
future = transformation(v);
@@ -223,10 +237,10 @@ class _FutureImpl<T> implements Future<T> {
} catch (innerException, stackTrace) {
completer.completeException(innerException, stackTrace);
}
- return true;
+ return false;
});
- then(completer.complete);
+ _handleSuccess(completer.complete);
return completer.future;
}
@@ -236,7 +250,7 @@ class _FutureImpl<T> implements Future<T> {
*/
_forward(Future future, Completer completer) {
_forwardException(future, completer);
- future.then(completer.complete);
+ future._handleSuccess(completer.complete);
}
/**
@@ -245,7 +259,7 @@ class _FutureImpl<T> implements Future<T> {
_forwardException(Future future, Completer completer) {
future.handleException((e) {
completer.completeException(e, future.stackTrace);
- return true;
+ return false;
});
}
}
« no previous file with comments | « no previous file | tests/co19/co19-compiler.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698