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 892 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |