| 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 137 |
| 138 void onData(void handleData(T event)) { | 138 void onData(void handleData(T event)) { |
| 139 if (handleData == null) handleData = _nullDataHandler; | 139 if (handleData == null) handleData = _nullDataHandler; |
| 140 // TODO(floitsch): the return type should be 'void', and the type | 140 // TODO(floitsch): the return type should be 'void', and the type |
| 141 // should be inferred. | 141 // should be inferred. |
| 142 _onData = _zone.registerUnaryCallback<dynamic, T>(handleData); | 142 _onData = _zone.registerUnaryCallback<dynamic, T>(handleData); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void onError(Function handleError) { | 145 void onError(Function handleError) { |
| 146 if (handleError == null) handleError = _nullErrorHandler; | 146 if (handleError == null) handleError = _nullErrorHandler; |
| 147 // We are not allowed to use 'void' as type argument for the generic type, | 147 _onError = _registerErrorHandler(handleError, _zone); |
| 148 // so we use 'dynamic' instead. | |
| 149 _onError = _registerErrorHandler<dynamic>(handleError, _zone); | |
| 150 } | 148 } |
| 151 | 149 |
| 152 void onDone(void handleDone()) { | 150 void onDone(void handleDone()) { |
| 153 if (handleDone == null) handleDone = _nullDoneHandler; | 151 if (handleDone == null) handleDone = _nullDoneHandler; |
| 154 _onDone = _zone.registerCallback(handleDone); | 152 _onDone = _zone.registerCallback(handleDone); |
| 155 } | 153 } |
| 156 | 154 |
| 157 void pause([Future resumeSignal]) { | 155 void pause([Future resumeSignal]) { |
| 158 if (_isCanceled) return; | 156 if (_isCanceled) return; |
| 159 bool wasPaused = _isPaused; | 157 bool wasPaused = _isPaused; |
| (...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 _subscription = stream.listen( | 999 _subscription = stream.listen( |
| 1002 _onData, onError: _onError, onDone: _onDone, cancelOnError: true); | 1000 _onData, onError: _onError, onDone: _onDone, cancelOnError: true); |
| 1003 var future = new _Future<bool>(); | 1001 var future = new _Future<bool>(); |
| 1004 _stateData = future; | 1002 _stateData = future; |
| 1005 return future; | 1003 return future; |
| 1006 } | 1004 } |
| 1007 return new _Future<bool>.immediate(false); | 1005 return new _Future<bool>.immediate(false); |
| 1008 } | 1006 } |
| 1009 | 1007 |
| 1010 Future cancel() { | 1008 Future cancel() { |
| 1011 StreamSubscription<T> subscription = _subscription; | 1009 StreamSubscription subscription = _subscription; |
| 1012 Object stateData = _stateData; | 1010 Object stateData = _stateData; |
| 1013 _stateData = null; | 1011 _stateData = null; |
| 1014 if (subscription != null) { | 1012 if (subscription != null) { |
| 1015 _subscription = null; | 1013 _subscription = null; |
| 1016 if (!_isPaused) { | 1014 if (!_isPaused) { |
| 1017 _Future<bool> future = stateData as Object /*=_Future<bool>*/; | 1015 _Future<bool> future = stateData as Object /*=_Future<bool>*/; |
| 1018 future._asyncComplete(false); | 1016 future._asyncComplete(false); |
| 1019 } | 1017 } |
| 1020 return subscription.cancel(); | 1018 return subscription.cancel(); |
| 1021 } | 1019 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1052 class _EmptyStream<T> extends Stream<T> { | 1050 class _EmptyStream<T> extends Stream<T> { |
| 1053 const _EmptyStream() : super._internal(); | 1051 const _EmptyStream() : super._internal(); |
| 1054 bool get isBroadcast => true; | 1052 bool get isBroadcast => true; |
| 1055 StreamSubscription<T> listen(void onData(T data), | 1053 StreamSubscription<T> listen(void onData(T data), |
| 1056 {Function onError, | 1054 {Function onError, |
| 1057 void onDone(), | 1055 void onDone(), |
| 1058 bool cancelOnError}) { | 1056 bool cancelOnError}) { |
| 1059 return new _DoneStreamSubscription<T>(onDone); | 1057 return new _DoneStreamSubscription<T>(onDone); |
| 1060 } | 1058 } |
| 1061 } | 1059 } |
| OLD | NEW |