Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1299)

Side by Side Diff: sdk/lib/async/stream.dart

Issue 13680002: StreamConsumer has an addStream and a close functions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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, dynamic> streamConsumer) { 239 Future pipe(StreamConsumer<T, dynamic> streamConsumer) {
240 // TODO(floitsch): switch to:
241 // streamConsumer.addStream(this).then((_) => streamConsumer.close());
240 return streamConsumer.consume(this); 242 return streamConsumer.consume(this);
241 } 243 }
242 244
243 /** 245 /**
244 * Chains this stream as the input of the provided [StreamTransformer]. 246 * Chains this stream as the input of the provided [StreamTransformer].
245 * 247 *
246 * Returns the result of [:streamTransformer.bind:] itself. 248 * Returns the result of [:streamTransformer.bind:] itself.
247 */ 249 */
248 Stream transform(StreamTransformer<T, dynamic> streamTransformer) { 250 Stream transform(StreamTransformer<T, dynamic> streamTransformer) {
249 return streamTransformer.bind(this); 251 return streamTransformer.bind(this);
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 968
967 969
968 /** 970 /**
969 * The target of a [Stream.pipe] call. 971 * The target of a [Stream.pipe] call.
970 * 972 *
971 * The [Stream.pipe] call will pass itself to this object, and then return 973 * The [Stream.pipe] call will pass itself to this object, and then return
972 * the resulting [Future]. The pipe should complete the future when it's 974 * the resulting [Future]. The pipe should complete the future when it's
973 * done. 975 * done.
974 */ 976 */
975 abstract class StreamConsumer<S, T> { 977 abstract class StreamConsumer<S, T> {
978 // TODO(floitsch): generic types.
979 // Currently not possible to add generic types, since they clash with other
980 // types that have already been used.
981 Future addStream(Stream<S> stream);
982 Future close();
983
984
985 /**
986 * Consume is deprecated. Use [addStream] followed by [close] instead.
987 */
976 Future<T> consume(Stream<S> stream); 988 Future<T> consume(Stream<S> stream);
977 } 989 }
978 990
979 991
980 /** 992 /**
981 * The target of a [Stream.transform] call. 993 * The target of a [Stream.transform] call.
982 * 994 *
983 * The [Stream.transform] call will pass itself to this object and then return 995 * The [Stream.transform] call will pass itself to this object and then return
984 * the resulting stream. 996 * the resulting stream.
985 */ 997 */
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 1204
1193 /* TODO(8997): Implement EventSink instead, */ 1205 /* TODO(8997): Implement EventSink instead, */
1194 class _EventOutputSinkWrapper<T> extends StreamSink<T> { 1206 class _EventOutputSinkWrapper<T> extends StreamSink<T> {
1195 _EventOutputSink _sink; 1207 _EventOutputSink _sink;
1196 _EventOutputSinkWrapper(this._sink); 1208 _EventOutputSinkWrapper(this._sink);
1197 1209
1198 void add(T data) { _sink._sendData(data); } 1210 void add(T data) { _sink._sendData(data); }
1199 void addError(AsyncError error) { _sink._sendError(error); } 1211 void addError(AsyncError error) { _sink._sendError(error); }
1200 void close() { _sink._sendDone(); } 1212 void close() { _sink._sendDone(); }
1201 } 1213 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698