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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 * in order. | 230 * in order. |
231 */ | 231 */ |
232 Stream expand(Iterable convert(T value)) { | 232 Stream expand(Iterable convert(T value)) { |
233 return new _ExpandStream<T, dynamic>(this, convert); | 233 return new _ExpandStream<T, dynamic>(this, convert); |
234 } | 234 } |
235 | 235 |
236 /** | 236 /** |
237 * Binds this stream as the input of the provided [StreamConsumer]. | 237 * Binds this stream as the input of the provided [StreamConsumer]. |
238 */ | 238 */ |
239 Future pipe(StreamConsumer<T> streamConsumer) { | 239 Future pipe(StreamConsumer<T> streamConsumer) { |
240 // TODO(floitsch): switch to: | 240 return streamConsumer.addStream(this).then((_) => streamConsumer.close()); |
241 // streamConsumer.addStream(this).then((_) => streamConsumer.close()); | |
242 return streamConsumer.consume(this); | |
243 } | 241 } |
244 | 242 |
245 /** | 243 /** |
246 * Chains this stream as the input of the provided [StreamTransformer]. | 244 * Chains this stream as the input of the provided [StreamTransformer]. |
247 * | 245 * |
248 * Returns the result of [:streamTransformer.bind:] itself. | 246 * Returns the result of [:streamTransformer.bind:] itself. |
249 */ | 247 */ |
250 Stream transform(StreamTransformer<T, dynamic> streamTransformer) { | 248 Stream transform(StreamTransformer<T, dynamic> streamTransformer) { |
251 return streamTransformer.bind(this); | 249 return streamTransformer.bind(this); |
252 } | 250 } |
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 /** | 882 /** |
885 * The target of a [Stream.pipe] call. | 883 * The target of a [Stream.pipe] call. |
886 * | 884 * |
887 * The [Stream.pipe] call will pass itself to this object, and then return | 885 * The [Stream.pipe] call will pass itself to this object, and then return |
888 * the resulting [Future]. The pipe should complete the future when it's | 886 * the resulting [Future]. The pipe should complete the future when it's |
889 * done. | 887 * done. |
890 */ | 888 */ |
891 abstract class StreamConsumer<S> { | 889 abstract class StreamConsumer<S> { |
892 Future addStream(Stream<S> stream); | 890 Future addStream(Stream<S> stream); |
893 Future close(); | 891 Future close(); |
894 | |
895 | |
896 /** | |
897 * Consume is deprecated. Use [addStream] followed by [close] instead. | |
898 */ | |
899 Future consume(Stream<S> stream); | |
900 } | 892 } |
901 | 893 |
902 | 894 |
903 /** | 895 /** |
904 * The target of a [Stream.transform] call. | 896 * The target of a [Stream.transform] call. |
905 * | 897 * |
906 * The [Stream.transform] call will pass itself to this object and then return | 898 * The [Stream.transform] call will pass itself to this object and then return |
907 * the resulting stream. | 899 * the resulting stream. |
908 */ | 900 */ |
909 abstract class StreamTransformer<S, T> { | 901 abstract class StreamTransformer<S, T> { |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1150 } | 1142 } |
1151 | 1143 |
1152 class _EventOutputSinkWrapper<T> extends EventSink<T> { | 1144 class _EventOutputSinkWrapper<T> extends EventSink<T> { |
1153 _EventOutputSink _sink; | 1145 _EventOutputSink _sink; |
1154 _EventOutputSinkWrapper(this._sink); | 1146 _EventOutputSinkWrapper(this._sink); |
1155 | 1147 |
1156 void add(T data) { _sink._sendData(data); } | 1148 void add(T data) { _sink._sendData(data); } |
1157 void addError(AsyncError error) { _sink._sendError(error); } | 1149 void addError(AsyncError error) { _sink._sendError(error); } |
1158 void close() { _sink._sendDone(); } | 1150 void close() { _sink._sendDone(); } |
1159 } | 1151 } |
OLD | NEW |