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; |
Anders Johnsen
2013/07/05 17:10:50
It's okay to type this _FutureImpl, and then avoid
floitsch
2013/07/05 18:08:19
I think I once had a _FutureImpl here, but Lasse a
Lasse Reichstein Nielsen
2013/07/05 18:49:43
The argument was that is that the field is public,
| |
12 bool _isComplete = false; | 12 bool _isComplete = false; |
13 final _Zone _zone = _Zone.current.fork(); | |
13 | 14 |
14 _Completer() : future = new _FutureImpl<T>() { | 15 _Completer() : future = new _FutureImpl<T>() { |
Anders Johnsen
2013/07/05 17:10:50
So Future have a Zone too, so why not just use tha
floitsch
2013/07/05 18:08:19
Right...
No need for Zones in the completer. Remov
Lasse Reichstein Nielsen
2013/07/05 18:49:43
My interpretation too. Can't you just use future._
floitsch
2013/07/05 18:51:46
Completer.zone is already removed.
| |
15 _FutureImpl futureImpl = future; | 16 _FutureImpl futureImpl = future; |
17 _zone.expectCallback(); | |
16 futureImpl._zone.expectCallback(); | 18 futureImpl._zone.expectCallback(); |
17 } | 19 } |
18 | 20 |
19 void _setFutureValue(T value); | 21 void _setFutureValue(T value); |
20 void _setFutureError(error); | 22 void _setFutureError(error); |
21 | 23 |
22 void complete([T value]) { | 24 void complete([T value]) { |
23 if (_isComplete) throw new StateError("Future already completed"); | 25 if (_isComplete) throw new StateError("Future already completed"); |
24 _isComplete = true; | 26 _isComplete = true; |
25 _FutureImpl futureImpl = future; | 27 _FutureImpl futureImpl = future; |
28 _zone.cancelCallbackExpectation(); | |
26 futureImpl._zone.cancelCallbackExpectation(); | 29 futureImpl._zone.cancelCallbackExpectation(); |
27 _setFutureValue(value); | 30 _setFutureValue(value); |
28 } | 31 } |
29 | 32 |
30 void completeError(Object error, [Object stackTrace = null]) { | 33 void completeError(Object error, [Object stackTrace = null]) { |
31 if (_isComplete) throw new StateError("Future already completed"); | 34 if (_isComplete) throw new StateError("Future already completed"); |
32 _isComplete = true; | 35 _isComplete = true; |
33 if (stackTrace != null) { | 36 if (stackTrace != null) { |
34 // Force the stack trace onto the error, even if it already had one. | 37 // Force the stack trace onto the error, even if it already had one. |
35 _attachStackTrace(error, stackTrace); | 38 _attachStackTrace(error, stackTrace); |
36 } | 39 } |
37 _FutureImpl futureImpl = future; | 40 _FutureImpl futureImpl = future; |
38 if (futureImpl._inSameErrorZone(_Zone.current)) { | 41 if (futureImpl._inSameErrorZone(_zone)) { |
Anders Johnsen
2013/07/05 17:10:50
futureImpl._zone and below?
floitsch
2013/07/05 18:08:19
Actually it must be the same zone now, so I could
| |
42 _zone.cancelCallbackExpectation(); | |
39 futureImpl._zone.cancelCallbackExpectation(); | 43 futureImpl._zone.cancelCallbackExpectation(); |
40 _setFutureError(error); | 44 _setFutureError(error); |
41 } else { | 45 } else { |
42 _Zone.current.handleUncaughtError(error); | 46 _zone.cancelCallbackExpectation(); |
47 _zone.handleUncaughtError(error); | |
43 } | 48 } |
44 } | 49 } |
45 | 50 |
46 bool get isCompleted => _isComplete; | 51 bool get isCompleted => _isComplete; |
47 } | 52 } |
48 | 53 |
49 class _AsyncCompleter<T> extends _Completer<T> { | 54 class _AsyncCompleter<T> extends _Completer<T> { |
50 void _setFutureValue(T value) { | 55 void _setFutureValue(T value) { |
51 _FutureImpl future = this.future; | 56 _FutureImpl future = this.future; |
52 runAsync(() { future._setValue(value); }); | 57 runAsync(() { future._setValue(value); }); |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
653 _setError(error); | 658 _setError(error); |
654 }, onError: _setError); | 659 }, onError: _setError); |
655 return; | 660 return; |
656 } | 661 } |
657 } catch (e, s) { | 662 } catch (e, s) { |
658 error = _asyncError(e, s); | 663 error = _asyncError(e, s); |
659 } | 664 } |
660 _setError(error); | 665 _setError(error); |
661 } | 666 } |
662 } | 667 } |
OLD | NEW |