Chromium Code Reviews| 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 1655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1666 /** | 1666 /** |
| 1667 * An [Iterable] like interface for the values of a [Stream]. | 1667 * An [Iterable] like interface for the values of a [Stream]. |
| 1668 * | 1668 * |
| 1669 * This wraps a [Stream] and a subscription on the stream. It listens | 1669 * This wraps a [Stream] and a subscription on the stream. It listens |
| 1670 * on the stream, and completes the future returned by [moveNext] when the | 1670 * on the stream, and completes the future returned by [moveNext] when the |
| 1671 * next value becomes available. | 1671 * next value becomes available. |
| 1672 */ | 1672 */ |
| 1673 abstract class StreamIterator<T> { | 1673 abstract class StreamIterator<T> { |
| 1674 | 1674 |
| 1675 /** Create a [StreamIterator] on [stream]. */ | 1675 /** Create a [StreamIterator] on [stream]. */ |
| 1676 factory StreamIterator(Stream<T> stream) | 1676 factory StreamIterator(Stream<T> stream) = _StreamIteratorImpl<T>; |
| 1677 // TODO(lrn): use redirecting factory constructor when type | |
| 1678 // arguments are supported. | |
| 1679 => new _StreamIteratorImpl<T>(stream); | |
| 1680 | 1677 |
| 1681 /** | 1678 /** |
| 1682 * Wait for the next stream value to be available. | 1679 * Wait for the next stream value to be available. |
| 1683 * | 1680 * |
| 1684 * It is not allowed to call this function again until the future has | 1681 * The function must not be called again until the future returned by a |
|
Søren Gjesse
2015/07/03 11:06:52
"must not": What happens if that is violated? Stat
Lasse Reichstein Nielsen
2015/07/03 11:21:17
Yes, it throws StateError. We don't document that.
| |
| 1685 * completed. If the returned future completes with anything except `true`, | 1682 * previous call is completed. |
| 1683 * When the returned future completes with `true`, a new event is available | |
| 1684 * and can be read from [current]. | |
| 1685 * | |
| 1686 * If the returned future completes with anything except `true` | |
| 1687 * (whether with another value or with an error), | |
|
Søren Gjesse
2015/07/03 11:06:52
When can "another value" be anything but false?
Lasse Reichstein Nielsen
2015/07/03 11:21:17
It *should* not, but this is an interface, but we
| |
| 1686 * the iterator is done, and no new value will ever be available. | 1688 * the iterator is done, and no new value will ever be available. |
| 1687 * | 1689 * |
| 1688 * The future may complete with an error, if the stream produces an error. | 1690 * The future may complete with an error, if the stream produces an error. |
| 1689 */ | 1691 */ |
| 1690 Future<bool> moveNext(); | 1692 Future<bool> moveNext(); |
| 1691 | 1693 |
| 1692 /** | 1694 /** |
| 1693 * The current value of the stream. | 1695 * The current value of the stream. |
| 1694 * | 1696 * |
| 1695 * Only valid when the future returned by [moveNext] completes with `true` | 1697 * Is `null` before the first call to [moveNext] and after a call to |
| 1696 * as value, and only until the next call to [moveNext]. | 1698 * `moveNext` completes with a `false` result or an error. |
| 1699 * | |
| 1700 * When a `moveNext` call completes with `true`, the `current` field holds | |
| 1701 * the most recent event of the stream, and it stays like that until the next | |
| 1702 * call to `moveNext`. | |
| 1703 * Between a call to `moveNext` and when its returned future completes, | |
| 1704 * the value is unspecified. | |
| 1697 */ | 1705 */ |
| 1698 T get current; | 1706 T get current; |
| 1699 | 1707 |
| 1700 /** | 1708 /** |
| 1701 * Cancels the stream iterator (and the underlying stream subscription) early. | 1709 * Cancels the stream iterator (and the underlying stream subscription) early. |
| 1702 * | 1710 * |
| 1703 * The stream iterator is automatically canceled if the [moveNext] future | 1711 * The stream iterator is automatically canceled if the [moveNext] future |
| 1704 * completes with either `false` or an error. | 1712 * completes with either `false` or an error. |
| 1705 * | 1713 * |
| 1706 * If a [moveNext] call has been made, it will complete with `false` as value, | |
| 1707 * as will all further calls to [moveNext]. | |
| 1708 * | |
| 1709 * If you need to stop listening for values before the stream iterator is | 1714 * If you need to stop listening for values before the stream iterator is |
| 1710 * automatically closed, you must call [cancel] to ensure that the stream | 1715 * automatically closed, you must call [cancel] to ensure that the stream |
| 1711 * is properly closed. | 1716 * is properly closed. |
| 1712 * | 1717 * |
| 1718 * If [moveNext] has been called when the iterator is cancelled, | |
| 1719 * its returned future will complete with `false` as value, | |
| 1720 * as will all further calls to [moveNext]. | |
|
Søren Gjesse
2015/07/03 11:06:52
So moveNext cannot distinguish between end of stre
Lasse Reichstein Nielsen
2015/07/03 11:21:17
I don't think it's worth it.
The code calling canc
| |
| 1721 * | |
| 1713 * Returns a future if the cancel-operation is not completed synchronously. | 1722 * Returns a future if the cancel-operation is not completed synchronously. |
| 1714 * Otherwise returns `null`. | 1723 * Otherwise returns `null`. |
| 1715 */ | 1724 */ |
| 1716 Future cancel(); | 1725 Future cancel(); |
| 1717 } | 1726 } |
| 1718 | 1727 |
| 1719 | 1728 |
| 1720 /** | 1729 /** |
| 1721 * Wraps an [_EventSink] so it exposes only the [EventSink] interface. | 1730 * Wraps an [_EventSink] so it exposes only the [EventSink] interface. |
| 1722 */ | 1731 */ |
| 1723 class _ControllerEventSinkWrapper<T> implements EventSink<T> { | 1732 class _ControllerEventSinkWrapper<T> implements EventSink<T> { |
| 1724 EventSink _sink; | 1733 EventSink _sink; |
| 1725 _ControllerEventSinkWrapper(this._sink); | 1734 _ControllerEventSinkWrapper(this._sink); |
| 1726 | 1735 |
| 1727 void add(T data) { _sink.add(data); } | 1736 void add(T data) { _sink.add(data); } |
| 1728 void addError(error, [StackTrace stackTrace]) { | 1737 void addError(error, [StackTrace stackTrace]) { |
| 1729 _sink.addError(error, stackTrace); | 1738 _sink.addError(error, stackTrace); |
| 1730 } | 1739 } |
| 1731 void close() { _sink.close(); } | 1740 void close() { _sink.close(); } |
| 1732 } | 1741 } |
| OLD | NEW |