| Index: sdk/lib/async/future_impl.dart
|
| diff --git a/sdk/lib/async/future_impl.dart b/sdk/lib/async/future_impl.dart
|
| index ea8f9027bd8494c05685abfb90eb9fcdc69c88b0..c8e8b33557f06ff6707a3c63cc3ae0770dafb0f3 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;
|
| @@ -155,21 +155,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),
|
| + _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;
|
| @@ -223,7 +226,7 @@ class _Future<T> implements Future<T> {
|
| assert(listener._nextListener == null);
|
| if (_isComplete) {
|
| // Handle late listeners asynchronously.
|
| - runAsync(() {
|
| + _zone.runAsync(() {
|
| _propagateToListeners(this, listener);
|
| });
|
| } else {
|
| @@ -332,7 +335,7 @@ class _Future<T> implements Future<T> {
|
| }
|
|
|
| _markPendingCompletion();
|
| - runAsync(() {
|
| + _zone.runAsync(() {
|
| _complete(value);
|
| });
|
| }
|
| @@ -345,7 +348,7 @@ class _Future<T> implements Future<T> {
|
| assert(_errorTest == null);
|
|
|
| _markPendingCompletion();
|
| - runAsync(() {
|
| + _zone.runAsync(() {
|
| _completeError(error, stackTrace);
|
| });
|
| }
|
| @@ -396,11 +399,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;
|
| @@ -420,7 +423,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).
|
| @@ -470,8 +473,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) {
|
| @@ -479,10 +480,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.
|
|
|