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

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

Issue 2822173002: Warn when adding something to a closed sink and improve documentation (Closed)
Patch Set: Improve documentation (issue 29122). Created 3 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
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 1445 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 * In case of an error the subscription will automatically cancel (even 1456 * In case of an error the subscription will automatically cancel (even
1457 * when it was listening with `cancelOnError` set to `false`). 1457 * when it was listening with `cancelOnError` set to `false`).
1458 * 1458 *
1459 * In case of a `done` event the future completes with the given 1459 * In case of a `done` event the future completes with the given
1460 * [futureValue]. 1460 * [futureValue].
1461 */ 1461 */
1462 Future<E> asFuture<E>([E futureValue]); 1462 Future<E> asFuture<E>([E futureValue]);
1463 } 1463 }
1464 1464
1465 /** 1465 /**
1466 * An interface that abstracts creation or handling of [Stream] events. 1466 * A [Sink] that supports adding errors and closing.
Lasse Reichstein Nielsen 2017/04/26 08:26:18 The [Sink] already supports closing, so it's redun
floitsch 2017/05/01 16:46:25 Done.
1467 */ 1467 */
1468 abstract class EventSink<T> implements Sink<T> { 1468 abstract class EventSink<T> implements Sink<T> {
Lasse Reichstein Nielsen 2017/04/26 08:26:19 The name "EventSink" comes from streams, so I'm no
floitsch 2017/05/01 16:46:24 Added a paragraph: * The [EventSink] has been des
1469 /** Send a data event to a stream. */ 1469 /**
1470 * Puts a data [event] into the sink.
Lasse Reichstein Nielsen 2017/04/26 08:26:19 Puts .. into -> Adds .. to We generally use "add"
floitsch 2017/05/01 16:46:25 Done.
1471 *
1472 * Must not be called on a closed sink.
1473 */
1470 void add(T event); 1474 void add(T event);
1471 1475
1472 /** Send an async error to a stream. */ 1476 /**
1477 * Puts an [errorEvent] into the sink.
1478 *
1479 * Must not be called on a closed sink.
1480 */
1473 void addError(Object errorEvent, [StackTrace stackTrace]); 1481 void addError(Object errorEvent, [StackTrace stackTrace]);
Lasse Reichstein Nielsen 2017/04/26 08:26:19 Hmm, errorEvent -> error. It's suspicious that the
floitsch 2017/05/01 16:46:25 Done.
1474 1482
1475 /** Close the sink. No further events can be added after closing. */ 1483 /**
1484 * Closes the sink.
1485 *
1486 * No further events can be added after closing.
Lasse Reichstein Nielsen 2017/04/26 08:26:19 Can you close more than once? What is an event? (
floitsch 2017/05/01 16:46:24 * Calling this method more than once is allowed, b
1487 */
1476 void close(); 1488 void close();
1477 } 1489 }
1478 1490
1479 /** [Stream] wrapper that only exposes the [Stream] interface. */ 1491 /** [Stream] wrapper that only exposes the [Stream] interface. */
1480 class StreamView<T> extends Stream<T> { 1492 class StreamView<T> extends Stream<T> {
1481 final Stream<T> _stream; 1493 final Stream<T> _stream;
1482 1494
1483 const StreamView(Stream<T> stream) 1495 const StreamView(Stream<T> stream)
1484 : _stream = stream, 1496 : _stream = stream,
1485 super._internal(); 1497 super._internal();
(...skipping 12 matching lines...) Expand all
1498 } 1510 }
1499 } 1511 }
1500 1512
1501 /** 1513 /**
1502 * Abstract interface for a "sink" accepting multiple entire streams. 1514 * Abstract interface for a "sink" accepting multiple entire streams.
1503 * 1515 *
1504 * A consumer can accept a number of consecutive streams using [addStream], 1516 * A consumer can accept a number of consecutive streams using [addStream],
1505 * and when no further data need to be added, the [close] method tells the 1517 * and when no further data need to be added, the [close] method tells the
1506 * consumer to complete its work and shut down. 1518 * consumer to complete its work and shut down.
1507 * 1519 *
1508 * This class is not just a [Sink<Stream>] because it is also combined with
1509 * other [Sink] classes, like it's combined with [EventSink] in the
1510 * [StreamSink] class.
1511 *
1512 * The [Stream.pipe] accepts a `StreamConsumer` and will pass the stream 1520 * The [Stream.pipe] accepts a `StreamConsumer` and will pass the stream
1513 * to the consumer's [addStream] method. When that completes, it will 1521 * to the consumer's [addStream] method. When that completes, it will
1514 * call [close] and then complete its own returned future. 1522 * call [close] and then complete its own returned future.
1515 */ 1523 */
1516 abstract class StreamConsumer<S> { 1524 abstract class StreamConsumer<S> {
1517 /** 1525 /**
1518 * Consumes the elements of [stream]. 1526 * Consumes the elements of [stream].
1519 * 1527 *
1520 * Listens on [stream] and does something for each event. 1528 * Listens on [stream] and does something for each event.
1521 * 1529 *
(...skipping 21 matching lines...) Expand all
1543 * Returns a future which is completed when the consumer has shut down. 1551 * Returns a future which is completed when the consumer has shut down.
1544 * If cleaning up can fail, the error may be reported in the returned future, 1552 * If cleaning up can fail, the error may be reported in the returned future,
1545 * otherwise it completes with `null`. 1553 * otherwise it completes with `null`.
1546 */ 1554 */
1547 Future close(); 1555 Future close();
1548 } 1556 }
1549 1557
1550 /** 1558 /**
1551 * A object that accepts stream events both synchronously and asynchronously. 1559 * A object that accepts stream events both synchronously and asynchronously.
1552 * 1560 *
1553 * A [StreamSink] unifies the asynchronous methods from [StreamConsumer] and 1561 * A [StreamSink] combines the methods from [StreamConsumer] and [EventSink].
1554 * the synchronous methods from [EventSink].
1555 * 1562 *
1556 * The [EventSink] methods can't be used while the [addStream] is called. 1563 * The [EventSink] methods can't be used while the [addStream] is called.
1557 * As soon as the [addStream]'s [Future] completes with a value, the 1564 * As soon as the [addStream]'s [Future] completes with a value, the
1558 * [EventSink] methods can be used again. 1565 * [EventSink] methods can be used again.
1559 * 1566 *
1560 * If [addStream] is called after any of the [EventSink] methods, it'll 1567 * If [addStream] is called after any of the [EventSink] methods, it'll
1561 * be delayed until the underlying system has consumed the data added by the 1568 * be delayed until the underlying system has consumed the data added by the
1562 * [EventSink] methods. 1569 * [EventSink] methods.
1563 * 1570 *
1564 * When [EventSink] methods are used, the [done] [Future] can be used to 1571 * When [EventSink] methods are used, the [done] [Future] can be used to
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1790 } 1797 }
1791 1798
1792 void addError(error, [StackTrace stackTrace]) { 1799 void addError(error, [StackTrace stackTrace]) {
1793 _sink.addError(error, stackTrace); 1800 _sink.addError(error, stackTrace);
1794 } 1801 }
1795 1802
1796 void close() { 1803 void close() {
1797 _sink.close(); 1804 _sink.close();
1798 } 1805 }
1799 } 1806 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698