| 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 980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 991 return new _Future<bool>.immediate(false); | 991 return new _Future<bool>.immediate(false); |
| 992 } | 992 } |
| 993 if (_state == _STATE_MOVING) { | 993 if (_state == _STATE_MOVING) { |
| 994 throw new StateError("Already waiting for next."); | 994 throw new StateError("Already waiting for next."); |
| 995 } | 995 } |
| 996 if (_state == _STATE_FOUND) { | 996 if (_state == _STATE_FOUND) { |
| 997 _state = _STATE_MOVING; | 997 _state = _STATE_MOVING; |
| 998 _current = null; | 998 _current = null; |
| 999 _futureOrPrefetch = new _Future<bool>(); | 999 _futureOrPrefetch = new _Future<bool>(); |
| 1000 return _futureOrPrefetch; | 1000 return _futureOrPrefetch; |
| 1001 } | 1001 } else { |
| 1002 assert(_state >= _STATE_EXTRA_DATA); | 1002 assert(_state >= _STATE_EXTRA_DATA); |
| 1003 switch (_state) { | 1003 switch (_state) { |
| 1004 case _STATE_EXTRA_DATA: | 1004 case _STATE_EXTRA_DATA: |
| 1005 _state = _STATE_FOUND; | 1005 _state = _STATE_FOUND; |
| 1006 _current = _futureOrPrefetch; | 1006 _current = _futureOrPrefetch; |
| 1007 _futureOrPrefetch = null; | 1007 _futureOrPrefetch = null; |
| 1008 _subscription.resume(); | 1008 _subscription.resume(); |
| 1009 return new _Future<bool>.immediate(true); | 1009 return new _Future<bool>.immediate(true); |
| 1010 case _STATE_EXTRA_ERROR: | 1010 case _STATE_EXTRA_ERROR: |
| 1011 AsyncError prefetch = _futureOrPrefetch; | 1011 AsyncError prefetch = _futureOrPrefetch; |
| 1012 _clear(); | 1012 _clear(); |
| 1013 return new _Future<bool>.immediateError(prefetch.error, | 1013 return new _Future<bool>.immediateError(prefetch.error, |
| 1014 prefetch.stackTrace); | 1014 prefetch.stackTrace); |
| 1015 case _STATE_EXTRA_DONE: | 1015 case _STATE_EXTRA_DONE: |
| 1016 _clear(); | 1016 _clear(); |
| 1017 return new _Future<bool>.immediate(false); | 1017 return new _Future<bool>.immediate(false); |
| 1018 default: | 1018 } |
| 1019 throw "Unreachable"; | |
| 1020 } | 1019 } |
| 1021 } | 1020 } |
| 1022 | 1021 |
| 1023 /** Clears up the internal state when the iterator ends. */ | 1022 /** Clears up the internal state when the iterator ends. */ |
| 1024 void _clear() { | 1023 void _clear() { |
| 1025 _subscription = null; | 1024 _subscription = null; |
| 1026 _futureOrPrefetch = null; | 1025 _futureOrPrefetch = null; |
| 1027 _current = null; | 1026 _current = null; |
| 1028 _state = _STATE_DONE; | 1027 _state = _STATE_DONE; |
| 1029 } | 1028 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1075 _Future<bool> hasNext = _futureOrPrefetch; | 1074 _Future<bool> hasNext = _futureOrPrefetch; |
| 1076 _clear(); | 1075 _clear(); |
| 1077 hasNext._complete(false); | 1076 hasNext._complete(false); |
| 1078 return; | 1077 return; |
| 1079 } | 1078 } |
| 1080 _subscription.pause(); | 1079 _subscription.pause(); |
| 1081 _futureOrPrefetch = null; | 1080 _futureOrPrefetch = null; |
| 1082 _state = _STATE_EXTRA_DONE; | 1081 _state = _STATE_EXTRA_DONE; |
| 1083 } | 1082 } |
| 1084 } | 1083 } |
| OLD | NEW |