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

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

Issue 17064008: Revert "Zone support for Futures." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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 | « sdk/lib/async/event_loop.dart ('k') | sdk/lib/async/stream_controller.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/async/future_impl.dart
diff --git a/sdk/lib/async/future_impl.dart b/sdk/lib/async/future_impl.dart
index be0b7a23229fff9d0acee3ff592698f11332e542..47c51ec63f84c10dbb0abc90039844689f550f4a 100644
--- a/sdk/lib/async/future_impl.dart
+++ b/sdk/lib/async/future_impl.dart
@@ -11,10 +11,7 @@ abstract class _Completer<T> implements Completer<T> {
final Future<T> future;
bool _isComplete = false;
- _Completer() : future = new _FutureImpl<T>() {
- _FutureImpl futureImpl = future;
- futureImpl._zone.expectCallback();
- }
+ _Completer() : future = new _FutureImpl<T>();
void _setFutureValue(T value);
void _setFutureError(error);
@@ -22,8 +19,6 @@ abstract class _Completer<T> implements Completer<T> {
void complete([T value]) {
if (_isComplete) throw new StateError("Future already completed");
_isComplete = true;
- _FutureImpl futureImpl = future;
- futureImpl._zone.cancelCallbackExpectation();
_setFutureValue(value);
}
@@ -34,13 +29,7 @@ abstract class _Completer<T> implements Completer<T> {
// Force the stack trace onto the error, even if it already had one.
_attachStackTrace(error, stackTrace);
}
- _FutureImpl futureImpl = future;
- if (futureImpl._inSameErrorZone(_Zone.current)) {
- futureImpl._zone.cancelCallbackExpectation();
- _setFutureError(error);
- } else {
- _Zone.current.handleUncaughtError(error);
- }
+ _setFutureError(error);
}
bool get isCompleted => _isComplete;
@@ -85,8 +74,6 @@ abstract class _FutureListener<T> {
}
void _sendValue(T value);
void _sendError(error);
-
- bool _inSameErrorZone(_Zone otherZone);
}
/** Adapter for a [_FutureImpl] to be a future result listener. */
@@ -96,61 +83,6 @@ class _FutureListenerWrapper<T> implements _FutureListener<T> {
_FutureListenerWrapper(this.future);
_sendValue(T value) { future._setValue(value); }
_sendError(error) { future._setError(error); }
- bool _inSameErrorZone(_Zone otherZone) => future._inSameErrorZone(otherZone);
-}
-
-/**
- * This listener is installed at error-zone boundaries. It signals an
- * uncaught error in the zone of origin when an error is sent from one error
- * zone to another.
- *
- * When a Future is listening to another Future and they have not been
- * instantiated in the same error-zone then Futures put an instance of this
- * class between them (see [_FutureImpl._addListener]).
- *
- * For example:
- *
- * var completer = new Completer();
- * var future = completer.future.then((x) => x);
- * catchErrors(() {
- * var future2 = future.catchError(print);
- * });
- * completer.completeError(499);
- *
- * In this example `future` and `future2` are in different error-zones. The
- * error (499) that originates outside `catchErrors` must not reach the
- * `catchError` future (`future2`) inside `catchErrors`.
- *
- * When invoking `catchError` on `future` the Future installs an
- * [_ErrorZoneBoundaryListener] between itself and the result, `future2`.
- *
- * Conceptually _ErrorZoneBoundaryListeners could be implemented as
- * `catchError`s on the origin future as well.
- */
-class _ErrorZoneBoundaryListener implements _FutureListener {
- _FutureListener _nextListener;
- final _FutureListener _listener;
-
- _ErrorZoneBoundaryListener(this._listener);
-
- bool _inSameErrorZone(_Zone otherZone) {
- // Should never be called. We use [_inSameErrorZone] to know if we have
- // to insert an instance of [_ErrorZoneBoundaryListener] (and in the
- // controller). Once we have inserted one we should never need to use it
- // anymore.
- throw new UnsupportedError(
- "A Zone boundary doesn't support the inSameErrorZone test.");
- }
-
- void _sendValue(value) {
- _listener._sendValue(value);
- }
-
- void _sendError(error) {
- // We are not allowed to send an error from one error-zone to another.
- // This is the whole purpose of this class.
- _Zone.current.handleUncaughtError(error);
- }
}
class _FutureImpl<T> implements Future<T> {
@@ -186,8 +118,6 @@ class _FutureImpl<T> implements Future<T> {
/** Whether the future is complete, and as what. */
int _state = _INCOMPLETE;
- final _Zone _zone = _Zone.current.fork();
-
bool get _isChained => (_state & _CHAINED) != 0;
bool get _hasChainedListener => _state == _CHAINED;
bool get _isComplete => _state >= _VALUE;
@@ -285,10 +215,6 @@ class _FutureImpl<T> implements Future<T> {
Stream<T> asStream() => new Stream.fromFuture(this);
- bool _inSameErrorZone(_Zone otherZone) {
- return _zone.inSameErrorZone(otherZone);
- }
-
void _setValue(T value) {
if (_isComplete) throw new StateError("Future already completed");
_FutureListener listeners = _isChained ? null : _removeListeners();
@@ -341,16 +267,17 @@ class _FutureImpl<T> implements Future<T> {
_clearUnhandledError();
// TODO(floitsch): Hook this into unhandled error handling.
var error = _resultOrListeners;
- _zone.handleUncaughtError(error);
+ print("Uncaught Error: ${error}");
+ var trace = getAttachedStackTrace(error);
+ if (trace != null) {
+ print("Stack Trace:\n$trace\n");
+ }
+ throw error;
}
});
}
void _addListener(_FutureListener listener) {
- assert(listener._nextListener == null);
- if (!listener._inSameErrorZone(_zone)) {
- listener = new _ErrorZoneBoundaryListener(listener);
- }
if (_isChained) {
_state = _CHAINED; // In case it was _CHAINED_UNLISTENED.
_FutureImpl resultSource = _chainSource;
@@ -371,6 +298,7 @@ class _FutureImpl<T> implements Future<T> {
});
} else {
assert(!_isComplete);
+ assert(listener._nextListener == null);
listener._nextListener = _resultOrListeners;
_resultOrListeners = listener;
}
@@ -506,24 +434,13 @@ abstract class _TransformFuture<S, T> extends _FutureImpl<T>
// _FutureListener implementation.
_FutureListener _nextListener;
- _TransformFuture() {
- _zone.expectCallback();
- }
+ void _sendValue(S value);
- void _sendValue(S value) {
- _zone.executeCallback(() => _zonedSendValue(value));
- }
-
- void _sendError(error) {
- _zone.executeCallback(() => _zonedSendError(error));
- }
+ void _sendError(error);
void _subscribeTo(_FutureImpl future) {
future._addListener(this);
}
-
- void _zonedSendValue(S value);
- void _zonedSendError(error);
}
/** The onValue and onError handlers return either a value or a future */
@@ -542,7 +459,7 @@ class _ThenFuture<S, T> extends _TransformFuture<S, T> {
_ThenFuture(this._onValue);
- _zonedSendValue(S value) {
+ _sendValue(S value) {
assert(_onValue != null);
var result;
try {
@@ -554,7 +471,7 @@ class _ThenFuture<S, T> extends _TransformFuture<S, T> {
_setOrChainValue(result);
}
- void _zonedSendError(error) {
+ void _sendError(error) {
_setError(error);
}
}
@@ -566,11 +483,11 @@ class _CatchErrorFuture<T> extends _TransformFuture<T,T> {
_CatchErrorFuture(this._onError, this._test);
- _zonedSendValue(T value) {
+ _sendValue(T value) {
_setValue(value);
}
- _zonedSendError(error) {
+ _sendError(error) {
assert(_onError != null);
// if _test is supplied, check if it returns true, otherwise just
// forward the error unmodified.
@@ -607,7 +524,7 @@ class _SubscribeFuture<S, T> extends _ThenFuture<S, T> {
// The _sendValue method is inherited from ThenFuture.
- void _zonedSendError(error) {
+ void _sendError(error) {
assert(_onError != null);
var result;
try {
@@ -626,7 +543,7 @@ class _WhenFuture<T> extends _TransformFuture<T, T> {
_WhenFuture(this._action);
- void _zonedSendValue(T value) {
+ void _sendValue(T value) {
try {
var result = _action();
if (result is Future) {
@@ -643,7 +560,7 @@ class _WhenFuture<T> extends _TransformFuture<T, T> {
_setValue(value);
}
- void _zonedSendError(error) {
+ void _sendError(error) {
try {
var result = _action();
if (result is Future) {
« no previous file with comments | « sdk/lib/async/event_loop.dart ('k') | sdk/lib/async/stream_controller.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698