Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart.async; | 5 part of dart.async; |
| 6 | 6 |
| 7 deprecatedFutureValue(_FutureImpl future) => | 7 deprecatedFutureValue(_FutureImpl future) => |
| 8 future._isComplete ? future._resultOrListeners : null; | 8 future._isComplete ? future._resultOrListeners : null; |
| 9 | 9 |
| 10 abstract class _Completer<T> implements Completer<T> { | 10 abstract class _Completer<T> implements Completer<T> { |
| 11 final Future<T> future; | 11 final Future<T> future; |
| 12 bool _isComplete = false; | 12 bool _isComplete = false; |
| 13 | 13 |
| 14 _Completer() : future = new _FutureImpl<T>() { | 14 _Completer() : future = new _FutureImpl<T>() { |
| 15 _FutureImpl futureImpl = future; | 15 _FutureImpl futureImpl = future; |
| 16 futureImpl._zone.expectCallback(); | 16 futureImpl._zone.expectCallback(); |
| 17 } | 17 } |
| 18 | 18 |
| 19 void _setFutureValue(T value); | 19 void _setFutureValue(T value); |
| 20 void _setFutureError(error); | 20 void _setFutureError(error); |
| 21 | 21 |
| 22 void complete([T value]) { | 22 void complete([T value]) { |
| 23 if (_isComplete) throw new StateError("Future already completed"); | 23 if (_isComplete) throw new StateError("Future already completed"); |
| 24 _isComplete = true; | 24 _isComplete = true; |
| 25 _FutureImpl futureImpl = future; | 25 _FutureImpl futureImpl = future; |
| 26 _setFutureValue(value); | |
| 26 futureImpl._zone.cancelCallbackExpectation(); | 27 futureImpl._zone.cancelCallbackExpectation(); |
| 27 _setFutureValue(value); | |
| 28 } | 28 } |
| 29 | 29 |
| 30 void completeError(Object error, [Object stackTrace = null]) { | 30 void completeError(Object error, [Object stackTrace = null]) { |
| 31 if (_isComplete) throw new StateError("Future already completed"); | 31 if (_isComplete) throw new StateError("Future already completed"); |
| 32 _isComplete = true; | 32 _isComplete = true; |
| 33 if (stackTrace != null) { | 33 if (stackTrace != null) { |
| 34 // Force the stack trace onto the error, even if it already had one. | 34 // Force the stack trace onto the error, even if it already had one. |
| 35 _attachStackTrace(error, stackTrace); | 35 _attachStackTrace(error, stackTrace); |
| 36 } | 36 } |
| 37 _FutureImpl futureImpl = future; | 37 _FutureImpl futureImpl = future; |
| 38 if (futureImpl._inSameErrorZone(_Zone.current)) { | 38 _setFutureError(error); |
| 39 futureImpl._zone.cancelCallbackExpectation(); | 39 futureImpl._zone.cancelCallbackExpectation(); |
|
Lasse Reichstein Nielsen
2013/07/05 19:00:07
Is this too early if _setFutureError is async? We
floitsch
2013/07/08 10:45:51
Moved it down to _setFutureValue and _setFutureErr
| |
| 40 _setFutureError(error); | |
| 41 } else { | |
| 42 _Zone.current.handleUncaughtError(error); | |
| 43 } | |
| 44 } | 40 } |
| 45 | 41 |
| 46 bool get isCompleted => _isComplete; | 42 bool get isCompleted => _isComplete; |
| 47 } | 43 } |
| 48 | 44 |
| 49 class _AsyncCompleter<T> extends _Completer<T> { | 45 class _AsyncCompleter<T> extends _Completer<T> { |
| 50 void _setFutureValue(T value) { | 46 void _setFutureValue(T value) { |
| 51 _FutureImpl future = this.future; | 47 _FutureImpl future = this.future; |
| 52 runAsync(() { future._setValue(value); }); | 48 runAsync(() { future._setValue(value); }); |
| 53 } | 49 } |
| (...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 653 _setError(error); | 649 _setError(error); |
| 654 }, onError: _setError); | 650 }, onError: _setError); |
| 655 return; | 651 return; |
| 656 } | 652 } |
| 657 } catch (e, s) { | 653 } catch (e, s) { |
| 658 error = _asyncError(e, s); | 654 error = _asyncError(e, s); |
| 659 } | 655 } |
| 660 _setError(error); | 656 _setError(error); |
| 661 } | 657 } |
| 662 } | 658 } |
| OLD | NEW |