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

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

Issue 23875032: Expose Zones. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Mark stack trace test as failing. Created 7 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: sdk/lib/async/future_impl.dart
diff --git a/sdk/lib/async/future_impl.dart b/sdk/lib/async/future_impl.dart
index a149161ba7ffef83552ca26fc74ec103d644aaed..3a541411e6fe878c30841ff5abc02a0346534ad6 100644
--- a/sdk/lib/async/future_impl.dart
+++ b/sdk/lib/async/future_impl.dart
@@ -76,7 +76,7 @@ class _Future<T> implements Future<T> {
/** Whether the future is complete, and as what. */
int _state = _INCOMPLETE;
- final _Zone _zone = _Zone.current.fork();
+ final Zone _zone = Zone.current;
bool get _mayComplete => _state == _INCOMPLETE;
bool get _isChained => _state == _CHAINED;
@@ -156,21 +156,24 @@ class _Future<T> implements Future<T> {
_asyncCompleteError(error, stackTrace);
}
- _Future._then(this._onValueCallback, this._onErrorCallback)
- : _errorTestCallback = null, _whenCompleteActionCallback = null {
- _zone.expectCallback();
- }
-
- _Future._catchError(this._onErrorCallback, this._errorTestCallback)
- : _onValueCallback = null, _whenCompleteActionCallback = null {
- _zone.expectCallback();
- }
-
- _Future._whenComplete(this._whenCompleteActionCallback)
- : _onValueCallback = null, _errorTestCallback = null,
- _onErrorCallback = null {
- _zone.expectCallback();
- }
+ _Future._then(onValueCallback(value), onErrorCallback(e))
+ : _onValueCallback = Zone._current.registerCallback1(onValueCallback),
Lasse Reichstein Nielsen 2013/09/23 14:24:12 This uses Zone._current here because that is the z
floitsch 2013/09/23 17:12:07 done. And made it Zone.current instead of Zone._cu
+ _onErrorCallback = Zone._current.registerCallback1(onErrorCallback),
+ _errorTestCallback = null,
+ _whenCompleteActionCallback = null;
+
+ _Future._catchError(onErrorCallback(e), bool errorTestCallback(e))
+ : _onErrorCallback = Zone._current.registerCallback1(onErrorCallback),
+ _errorTestCallback = Zone._current.registerCallback1(errorTestCallback),
+ _onValueCallback = null,
+ _whenCompleteActionCallback = null;
+
+ _Future._whenComplete(whenCompleteActionCallback())
+ : _whenCompleteActionCallback =
+ Zone._current.registerCallback(whenCompleteActionCallback),
+ _onValueCallback = null,
+ _errorTestCallback = null,
+ _onErrorCallback = null;
Future then(f(T value), { onError(error) }) {
_Future result;
@@ -224,7 +227,7 @@ class _Future<T> implements Future<T> {
assert(listener._nextListener == null);
if (_isComplete) {
// Handle late listeners asynchronously.
- runAsync(() {
+ _zone.scheduleMicrotask(() {
_propagateToListeners(this, listener);
});
} else {
@@ -341,7 +344,7 @@ class _Future<T> implements Future<T> {
}
_markPendingCompletion();
- runAsync(() {
+ _zone.scheduleMicrotask(() {
_complete(value);
});
}
@@ -354,7 +357,7 @@ class _Future<T> implements Future<T> {
assert(_errorTest == null);
_markPendingCompletion();
- runAsync(() {
+ _zone.scheduleMicrotask(() {
_completeError(error, stackTrace);
});
}
@@ -405,11 +408,11 @@ class _Future<T> implements Future<T> {
source._zone.handleUncaughtError(source._error);
return;
}
- if (!identical(_Zone.current, listener._zone)) {
+ if (!identical(Zone.current, listener._zone)) {
// Run the propagation in the listener's zone to avoid
// zone transitions. The idea is that many chained futures will
// be in the same zone.
- listener._zone.executePeriodicCallback(() {
+ listener._zone.run(() {
_propagateToListeners(source, listener);
});
return;
@@ -429,7 +432,7 @@ class _Future<T> implements Future<T> {
// zone.
// TODO(floitsch): only run callbacks in the zone, not the whole
// handling code.
- listener._zone.executeCallback(() {
+ listener._zone.run(() {
// TODO(floitsch): mark the listener as pending completion. Currently
// we can't do this, since the markPendingCompletion verifies that
// the future is not already marked (or chained).
@@ -479,8 +482,6 @@ class _Future<T> implements Future<T> {
_propagateToListeners(completeResult, listener);
});
isPropagationAborted = true;
- // We will reenter the listener's zone.
- listener._zone.expectCallback();
}
}
} catch (e, s) {
@@ -488,10 +489,6 @@ class _Future<T> implements Future<T> {
listenerValueOrError = _asyncError(e, s);
listenerHasValue = false;
}
- if (listenerHasValue && listenerValueOrError is Future) {
- // We are going to reenter the zone to finish what we started.
- listener._zone.expectCallback();
- }
});
if (isPropagationAborted) return;
// If the listener's value is a future we need to chain it.

Powered by Google App Engine
This is Rietveld 408576698