| 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 /** Utility function to create an [AsyncError] if [error] isn't one already. */ | 7 /** Utility function to create an [AsyncError] if [error] isn't one already. */ |
| 8 AsyncError _asyncError(Object error, Object stackTrace, [AsyncError cause]) { | 8 AsyncError _asyncError(Object error, Object stackTrace, [AsyncError cause]) { |
| 9 if (error is AsyncError) return error; | 9 if (error is AsyncError) return error; |
| 10 if (cause == null) return new AsyncError(error, stackTrace); | 10 if (cause == null) return new AsyncError(error, stackTrace); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 // Don't unsubscribe on incoming error, only if we send an error forwards. | 151 // Don't unsubscribe on incoming error, only if we send an error forwards. |
| 152 _subscription = | 152 _subscription = |
| 153 _stream._source.listen(_handleData, | 153 _stream._source.listen(_handleData, |
| 154 onError: _handleError, | 154 onError: _handleError, |
| 155 onDone: _handleDone); | 155 onDone: _handleDone); |
| 156 } | 156 } |
| 157 | 157 |
| 158 // StreamSubscription interface. | 158 // StreamSubscription interface. |
| 159 | 159 |
| 160 void pause([Future resumeSignal]) { | 160 void pause([Future resumeSignal]) { |
| 161 if (_subscription == null) { | 161 if (_subscription == null) return; |
| 162 throw new StateError("Subscription has been unsubscribed"); | |
| 163 } | |
| 164 _subscription.pause(resumeSignal); | 162 _subscription.pause(resumeSignal); |
| 165 } | 163 } |
| 166 | 164 |
| 167 void resume() { | 165 void resume() { |
| 168 if (_subscription == null) { | 166 if (_subscription == null) return; |
| 169 throw new StateError("Subscription has been unsubscribed"); | |
| 170 } | |
| 171 _subscription.resume(); | 167 _subscription.resume(); |
| 172 } | 168 } |
| 173 | 169 |
| 174 void cancel() { | 170 void cancel() { |
| 175 if (_subscription == null) { | 171 if (_subscription != null) { |
| 176 throw new StateError("Subscription has been unsubscribed"); | 172 _subscription.cancel(); |
| 173 _subscription = null; |
| 177 } | 174 } |
| 178 _subscription.cancel(); | |
| 179 _subscription = null; | |
| 180 } | 175 } |
| 181 | 176 |
| 182 // _EventOutputSink interface. Sends data to this subscription. | 177 // _EventOutputSink interface. Sends data to this subscription. |
| 183 | 178 |
| 184 void _sendData(T data) { | 179 void _sendData(T data) { |
| 185 _onData(data); | 180 _onData(data); |
| 186 } | 181 } |
| 187 | 182 |
| 188 void _sendError(AsyncError error) { | 183 void _sendError(AsyncError error) { |
| 189 _onError(error); | 184 _onError(error); |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 | 513 |
| 519 void handleError(AsyncError error, EventSink<T> sink) { | 514 void handleError(AsyncError error, EventSink<T> sink) { |
| 520 _handleError(error, sink); | 515 _handleError(error, sink); |
| 521 } | 516 } |
| 522 | 517 |
| 523 void handleDone(EventSink<T> sink) { | 518 void handleDone(EventSink<T> sink) { |
| 524 _handleDone(sink); | 519 _handleDone(sink); |
| 525 } | 520 } |
| 526 } | 521 } |
| 527 | 522 |
| OLD | NEW |