OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // ------------------------------------------------------------------- | 7 // ------------------------------------------------------------------- |
8 // Core Stream types | 8 // Core Stream types |
9 // ------------------------------------------------------------------- | 9 // ------------------------------------------------------------------- |
10 | 10 |
(...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
914 void pause([Future resumeSignal]); | 914 void pause([Future resumeSignal]); |
915 | 915 |
916 /** | 916 /** |
917 * Resume after a pause. | 917 * Resume after a pause. |
918 */ | 918 */ |
919 void resume(); | 919 void resume(); |
920 } | 920 } |
921 | 921 |
922 | 922 |
923 /** | 923 /** |
924 * *Deprecated*. Use [EventSink] instead. | |
925 */ | |
926 abstract class StreamSink<T> extends EventSink<T>{ | |
927 /* TODO(8997): Remove class.*/ | |
928 /** *Deprecated*. Use [EventSink.addError] instead.*/ | |
929 void signalError(AsyncError errorEvent) { addError(errorEvent); } | |
930 } | |
931 | |
932 | |
933 /** | |
934 * An interface that abstracts creation or handling of [Stream] events. | 924 * An interface that abstracts creation or handling of [Stream] events. |
935 */ | 925 */ |
936 abstract class EventSink<T> { | 926 abstract class EventSink<T> { |
937 /** Create a data event */ | 927 /** Create a data event */ |
938 void add(T event); | 928 void add(T event); |
939 /** Create an async error. */ | 929 /** Create an async error. */ |
940 void addError(AsyncError errorEvent); | 930 void addError(AsyncError errorEvent); |
941 /** Request a stream to close. */ | 931 /** Request a stream to close. */ |
942 void close(); | 932 close(); |
floitsch
2013/04/11 12:45:01
keep.
The EventSink.close should be assumed not to
Anders Johnsen
2013/04/11 12:53:05
Done.
| |
943 } | 933 } |
944 | 934 |
945 | 935 |
946 /** [Stream] wrapper that only exposes the [Stream] interface. */ | 936 /** [Stream] wrapper that only exposes the [Stream] interface. */ |
947 class StreamView<T> extends Stream<T> { | 937 class StreamView<T> extends Stream<T> { |
948 Stream<T> _stream; | 938 Stream<T> _stream; |
949 | 939 |
950 StreamView(this._stream); | 940 StreamView(this._stream); |
951 | 941 |
952 bool get isBroadcast => _stream.isBroadcast; | 942 bool get isBroadcast => _stream.isBroadcast; |
953 | 943 |
954 Stream<T> asBroadcastStream() => _stream.asBroadcastStream(); | 944 Stream<T> asBroadcastStream() => _stream.asBroadcastStream(); |
955 | 945 |
956 StreamSubscription<T> listen(void onData(T value), | 946 StreamSubscription<T> listen(void onData(T value), |
957 { void onError(AsyncError error), | 947 { void onError(AsyncError error), |
958 void onDone(), | 948 void onDone(), |
959 bool unsubscribeOnError }) { | 949 bool unsubscribeOnError }) { |
960 return _stream.listen(onData, onError: onError, onDone: onDone, | 950 return _stream.listen(onData, onError: onError, onDone: onDone, |
961 unsubscribeOnError: unsubscribeOnError); | 951 unsubscribeOnError: unsubscribeOnError); |
962 } | 952 } |
963 } | 953 } |
964 | 954 |
965 /** | 955 /** |
966 * [EventSink] wrapper that only exposes the [EventSink] interface. | 956 * [EventSink] wrapper that only exposes the [EventSink] interface. |
967 */ | 957 */ |
968 class EventSinkView<T> extends StreamSink<T> { | 958 class EventSinkView<T> extends EventSink<T> { |
969 // TODO(8997): Implment EventSink instead. | 959 // TODO(8997): Implment EventSink instead. |
970 final EventSink<T> _sink; | 960 final EventSink<T> _sink; |
971 | 961 |
972 EventSinkView(this._sink); | 962 EventSinkView(this._sink); |
973 | 963 |
974 void add(T value) { _sink.add(value); } | 964 void add(T value) { _sink.add(value); } |
975 void addError(AsyncError error) { _sink.addError(error); } | 965 void addError(AsyncError error) { _sink.addError(error); } |
976 void close() { _sink.close(); } | 966 void close() { _sink.close(); } |
977 } | 967 } |
978 | 968 |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1218 if (_isClosed) throw new StateError("Already closed."); | 1208 if (_isClosed) throw new StateError("Already closed."); |
1219 _isClosed = true; | 1209 _isClosed = true; |
1220 if (_isSubscribed) { | 1210 if (_isSubscribed) { |
1221 _subscription.cancel(); | 1211 _subscription.cancel(); |
1222 _subscription = null; | 1212 _subscription = null; |
1223 } | 1213 } |
1224 _onDone(); | 1214 _onDone(); |
1225 } | 1215 } |
1226 } | 1216 } |
1227 | 1217 |
1228 /* TODO(8997): Implement EventSink instead, */ | 1218 /* TODO(8997): Implement EventSink instead, */ |
floitsch
2013/04/11 12:45:01
Remove TODO.
Anders Johnsen
2013/04/11 12:53:05
Done.
| |
1229 class _EventOutputSinkWrapper<T> extends StreamSink<T> { | 1219 class _EventOutputSinkWrapper<T> extends EventSink<T> { |
1230 _EventOutputSink _sink; | 1220 _EventOutputSink _sink; |
1231 _EventOutputSinkWrapper(this._sink); | 1221 _EventOutputSinkWrapper(this._sink); |
1232 | 1222 |
1233 void add(T data) { _sink._sendData(data); } | 1223 void add(T data) { _sink._sendData(data); } |
1234 void addError(AsyncError error) { _sink._sendError(error); } | 1224 void addError(AsyncError error) { _sink._sendError(error); } |
1235 void close() { _sink._sendDone(); } | 1225 void close() { _sink._sendDone(); } |
1236 } | 1226 } |
OLD | NEW |