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

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

Issue 2864863002: Update StreamTransformer documentation. (Closed)
Patch Set: Address comments. Created 3 years, 7 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
« no previous file with comments | « sdk/lib/async/stream.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 * Wraps an [_EventSink] so it exposes only the [EventSink] interface. 8 * Wraps an [_EventSink] so it exposes only the [EventSink] interface.
9 */ 9 */
10 class _EventSinkWrapper<T> implements EventSink<T> { 10 class _EventSinkWrapper<T> implements EventSink<T> {
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 * Instead of implementing three classes: a [StreamTransformer], a [Stream] 269 * Instead of implementing three classes: a [StreamTransformer], a [Stream]
270 * (as the result of a `bind` call) and a [StreamSubscription] (which does the 270 * (as the result of a `bind` call) and a [StreamSubscription] (which does the
271 * actual work), this class only requires a function that is invoked when the 271 * actual work), this class only requires a function that is invoked when the
272 * last bit (the subscription) of the transformer-workflow is needed. 272 * last bit (the subscription) of the transformer-workflow is needed.
273 * 273 *
274 * The given transformer function maps from Stream and cancelOnError to a 274 * The given transformer function maps from Stream and cancelOnError to a
275 * `StreamSubscription`. As such it can also act on `cancel` events, making it 275 * `StreamSubscription`. As such it can also act on `cancel` events, making it
276 * fully general. 276 * fully general.
277 */ 277 */
278 class _StreamSubscriptionTransformer<S, T> implements StreamTransformer<S, T> { 278 class _StreamSubscriptionTransformer<S, T> implements StreamTransformer<S, T> {
279 final _SubscriptionTransformer<S, T> _transformer; 279 final _SubscriptionTransformer<S, T> _onListen;
280 280
281 const _StreamSubscriptionTransformer(this._transformer); 281 const _StreamSubscriptionTransformer(this._onListen);
282 282
283 Stream<T> bind(Stream<S> stream) => 283 Stream<T> bind(Stream<S> stream) =>
284 new _BoundSubscriptionStream<S, T>(stream, _transformer); 284 new _BoundSubscriptionStream<S, T>(stream, _onListen);
285 } 285 }
286 286
287 /** 287 /**
288 * A stream transformed by a [_StreamSubscriptionTransformer]. 288 * A stream transformed by a [_StreamSubscriptionTransformer].
289 * 289 *
290 * When this stream is listened to it invokes the [_transformer] function with 290 * When this stream is listened to it invokes the [_onListen] function with
291 * the stored [_stream]. Usually the transformer starts listening at this 291 * the stored [_stream]. Usually the transformer starts listening at this
292 * moment. 292 * moment.
293 */ 293 */
294 class _BoundSubscriptionStream<S, T> extends Stream<T> { 294 class _BoundSubscriptionStream<S, T> extends Stream<T> {
295 final _SubscriptionTransformer<S, T> _transformer; 295 final _SubscriptionTransformer<S, T> _onListen;
296 final Stream<S> _stream; 296 final Stream<S> _stream;
297 297
298 _BoundSubscriptionStream(this._stream, this._transformer); 298 _BoundSubscriptionStream(this._stream, this._onListen);
299 299
300 StreamSubscription<T> listen(void onData(T event), 300 StreamSubscription<T> listen(void onData(T event),
301 {Function onError, void onDone(), bool cancelOnError}) { 301 {Function onError, void onDone(), bool cancelOnError}) {
302 cancelOnError = identical(true, cancelOnError); 302 cancelOnError = identical(true, cancelOnError);
303 StreamSubscription<T> result = _transformer(_stream, cancelOnError); 303 StreamSubscription<T> result = _onListen(_stream, cancelOnError);
304 result.onData(onData); 304 result.onData(onData);
305 result.onError(onError); 305 result.onError(onError);
306 result.onDone(onDone); 306 result.onDone(onDone);
307 return result; 307 return result;
308 } 308 }
309 } 309 }
OLDNEW
« no previous file with comments | « sdk/lib/async/stream.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698