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

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

Issue 2119153002: Update documentation for Stream.listen. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 5 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 | « no previous file | 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 // Core Stream types 8 // Core Stream types
9 // ------------------------------------------------------------------- 9 // -------------------------------------------------------------------
10 10
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 */ 309 */
310 Stream<T> asBroadcastStream({ 310 Stream<T> asBroadcastStream({
311 void onListen(StreamSubscription<T> subscription), 311 void onListen(StreamSubscription<T> subscription),
312 void onCancel(StreamSubscription<T> subscription) }) { 312 void onCancel(StreamSubscription<T> subscription) }) {
313 return new _AsBroadcastStream<T>(this, onListen, onCancel); 313 return new _AsBroadcastStream<T>(this, onListen, onCancel);
314 } 314 }
315 315
316 /** 316 /**
317 * Adds a subscription to this stream. 317 * Adds a subscription to this stream.
318 * 318 *
319 * Returns a [StreamSubscription] which handles events from the stream using
320 * the provided [onData], [onError] and [onDone] handlers.
321 * The handlers can be changed on the subscription, but they start out
322 * as the provided functions.
323 *
319 * On each data event from this stream, the subscriber's [onData] handler 324 * On each data event from this stream, the subscriber's [onData] handler
320 * is called. If [onData] is null, nothing happens. 325 * is called. If [onData] is `null`, nothing happens.
321 * 326 *
322 * On errors from this stream, the [onError] handler is given a 327 * On errors from this stream, the [onError] handler is called with the
323 * object describing the error. 328 * error object and possibly a stack trace.
324 * 329 *
325 * The [onError] callback must be of type `void onError(error)` or 330 * The [onError] callback must be of type `void onError(error)` or
326 * `void onError(error, StackTrace stackTrace)`. If [onError] accepts 331 * `void onError(error, StackTrace stackTrace)`. If [onError] accepts
327 * two arguments it is called with the stack trace (which could be `null` if 332 * two arguments it is called with the error object and the stack trace
328 * the stream itself received an error without stack trace). 333 * (which could be `null` if the stream itself received an error without
334 * stack trace).
329 * Otherwise it is called with just the error object. 335 * Otherwise it is called with just the error object.
330 * If [onError] is omitted, any errors on the stream are considered unhandled, 336 * If [onError] is omitted, any errors on the stream are considered unhandled,
331 * and will be passed to the current [Zone]'s error handler. 337 * and will be passed to the current [Zone]'s error handler.
332 * By default unhandled async errors are treated 338 * By default unhandled async errors are treated
333 * as if they were uncaught top-level errors. 339 * as if they were uncaught top-level errors.
334 * 340 *
335 * If this stream closes, the [onDone] handler is called. 341 * If this stream closes and sends a done event, the [onDone] handler is
342 * called. If [onDone] is `null`, nothing happens.
336 * 343 *
337 * If [cancelOnError] is true, the subscription is ended when 344 * If [cancelOnError] is true, the subscription is automatically cancelled
338 * the first error is reported. The default is false. 345 * when the first error event is delivered. The default is `false`.
346 *
347 * While a subscription is paused, or when it has been cancelled,
348 * the subscription doesn't receive events and none of the
349 * event handler functions are called.
339 */ 350 */
340 StreamSubscription<T> listen(void onData(T event), 351 StreamSubscription<T> listen(void onData(T event),
341 { Function onError, 352 { Function onError,
342 void onDone(), 353 void onDone(),
343 bool cancelOnError}); 354 bool cancelOnError});
344 355
345 /** 356 /**
346 * Creates a new stream from this stream that discards some data events. 357 * Creates a new stream from this stream that discards some data events.
347 * 358 *
348 * The new stream sends the same error and done events as this stream, 359 * The new stream sends the same error and done events as this stream,
(...skipping 1462 matching lines...) Expand 10 before | Expand all | Expand 10 after
1811 class _ControllerEventSinkWrapper<T> implements EventSink<T> { 1822 class _ControllerEventSinkWrapper<T> implements EventSink<T> {
1812 EventSink _sink; 1823 EventSink _sink;
1813 _ControllerEventSinkWrapper(this._sink); 1824 _ControllerEventSinkWrapper(this._sink);
1814 1825
1815 void add(T data) { _sink.add(data); } 1826 void add(T data) { _sink.add(data); }
1816 void addError(error, [StackTrace stackTrace]) { 1827 void addError(error, [StackTrace stackTrace]) {
1817 _sink.addError(error, stackTrace); 1828 _sink.addError(error, stackTrace);
1818 } 1829 }
1819 void close() { _sink.close(); } 1830 void close() { _sink.close(); }
1820 } 1831 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698