| 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 /** Abstract and private interface for a place to put events. */ | 7 /** Abstract and private interface for a place to put events. */ |
| 8 abstract class _EventSink<T> { | 8 abstract class _EventSink<T> { |
| 9 void _add(T data); | 9 void _add(T data); |
| 10 void _addError(Object error, StackTrace stackTrace); | 10 void _addError(Object error, StackTrace stackTrace); |
| (...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1022 /** Clears up the internal state when the iterator ends. */ | 1022 /** Clears up the internal state when the iterator ends. */ |
| 1023 void _clear() { | 1023 void _clear() { |
| 1024 _subscription = null; | 1024 _subscription = null; |
| 1025 _futureOrPrefetch = null; | 1025 _futureOrPrefetch = null; |
| 1026 _current = null; | 1026 _current = null; |
| 1027 _state = _STATE_DONE; | 1027 _state = _STATE_DONE; |
| 1028 } | 1028 } |
| 1029 | 1029 |
| 1030 Future cancel() { | 1030 Future cancel() { |
| 1031 StreamSubscription subscription = _subscription; | 1031 StreamSubscription subscription = _subscription; |
| 1032 // Cherry pick of: https://codereview.chromium.org//896793002 |
| 1033 if (subscription == null) return null; |
| 1032 if (_state == _STATE_MOVING) { | 1034 if (_state == _STATE_MOVING) { |
| 1033 _Future<bool> hasNext = _futureOrPrefetch; | 1035 _Future<bool> hasNext = _futureOrPrefetch; |
| 1034 _clear(); | 1036 _clear(); |
| 1035 hasNext._complete(false); | 1037 hasNext._complete(false); |
| 1036 } else { | 1038 } else { |
| 1037 _clear(); | 1039 _clear(); |
| 1038 } | 1040 } |
| 1039 return subscription.cancel(); | 1041 return subscription.cancel(); |
| 1040 } | 1042 } |
| 1041 | 1043 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1073 _Future<bool> hasNext = _futureOrPrefetch; | 1075 _Future<bool> hasNext = _futureOrPrefetch; |
| 1074 _clear(); | 1076 _clear(); |
| 1075 hasNext._complete(false); | 1077 hasNext._complete(false); |
| 1076 return; | 1078 return; |
| 1077 } | 1079 } |
| 1078 _subscription.pause(); | 1080 _subscription.pause(); |
| 1079 _futureOrPrefetch = null; | 1081 _futureOrPrefetch = null; |
| 1080 _state = _STATE_EXTRA_DONE; | 1082 _state = _STATE_EXTRA_DONE; |
| 1081 } | 1083 } |
| 1082 } | 1084 } |
| OLD | NEW |