| 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 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 } else { | 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 Object prefetch = _futureOrPrefetch; | 1011 AsyncError prefetch = _futureOrPrefetch; |
| 1012 _clear(); | 1012 _clear(); |
| 1013 return new _Future<bool>.immediateError(prefetch); | 1013 return new _Future<bool>.immediateError(prefetch.error, |
| 1014 prefetch.stackTrace); |
| 1014 case _STATE_EXTRA_DONE: | 1015 case _STATE_EXTRA_DONE: |
| 1015 _clear(); | 1016 _clear(); |
| 1016 return new _Future<bool>.immediate(false); | 1017 return new _Future<bool>.immediate(false); |
| 1017 } | 1018 } |
| 1018 } | 1019 } |
| 1019 } | 1020 } |
| 1020 | 1021 |
| 1021 /** Clears up the internal state when the iterator ends. */ | 1022 /** Clears up the internal state when the iterator ends. */ |
| 1022 void _clear() { | 1023 void _clear() { |
| 1023 _subscription = null; | 1024 _subscription = null; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1056 void _onError(Object error, [StackTrace stackTrace]) { | 1057 void _onError(Object error, [StackTrace stackTrace]) { |
| 1057 if (_state == _STATE_MOVING) { | 1058 if (_state == _STATE_MOVING) { |
| 1058 _Future<bool> hasNext = _futureOrPrefetch; | 1059 _Future<bool> hasNext = _futureOrPrefetch; |
| 1059 // We have cancelOnError: true, so the subscription is canceled. | 1060 // We have cancelOnError: true, so the subscription is canceled. |
| 1060 _clear(); | 1061 _clear(); |
| 1061 hasNext._completeError(error, stackTrace); | 1062 hasNext._completeError(error, stackTrace); |
| 1062 return; | 1063 return; |
| 1063 } | 1064 } |
| 1064 _subscription.pause(); | 1065 _subscription.pause(); |
| 1065 assert(_futureOrPrefetch == null); | 1066 assert(_futureOrPrefetch == null); |
| 1066 _futureOrPrefetch = error; | 1067 _futureOrPrefetch = new AsyncError(error, stackTrace); |
| 1067 _state = _STATE_EXTRA_ERROR; | 1068 _state = _STATE_EXTRA_ERROR; |
| 1068 } | 1069 } |
| 1069 | 1070 |
| 1070 void _onDone() { | 1071 void _onDone() { |
| 1071 if (_state == _STATE_MOVING) { | 1072 if (_state == _STATE_MOVING) { |
| 1072 _Future<bool> hasNext = _futureOrPrefetch; | 1073 _Future<bool> hasNext = _futureOrPrefetch; |
| 1073 _clear(); | 1074 _clear(); |
| 1074 hasNext._complete(false); | 1075 hasNext._complete(false); |
| 1075 return; | 1076 return; |
| 1076 } | 1077 } |
| 1077 _subscription.pause(); | 1078 _subscription.pause(); |
| 1078 _futureOrPrefetch = null; | 1079 _futureOrPrefetch = null; |
| 1079 _state = _STATE_EXTRA_DONE; | 1080 _state = _STATE_EXTRA_DONE; |
| 1080 } | 1081 } |
| 1081 } | 1082 } |
| OLD | NEW |