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 1749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1760 * This wraps a [Stream] and a subscription on the stream. It listens | 1760 * This wraps a [Stream] and a subscription on the stream. It listens |
1761 * on the stream, and completes the future returned by [moveNext] when the | 1761 * on the stream, and completes the future returned by [moveNext] when the |
1762 * next value becomes available. | 1762 * next value becomes available. |
1763 */ | 1763 */ |
1764 abstract class StreamIterator<T> { | 1764 abstract class StreamIterator<T> { |
1765 | 1765 |
1766 /** Create a [StreamIterator] on [stream]. */ | 1766 /** Create a [StreamIterator] on [stream]. */ |
1767 factory StreamIterator(Stream<T> stream) | 1767 factory StreamIterator(Stream<T> stream) |
1768 // TODO(lrn): use redirecting factory constructor when type | 1768 // TODO(lrn): use redirecting factory constructor when type |
1769 // arguments are supported. | 1769 // arguments are supported. |
1770 => new _StreamIteratorImpl<T>(stream); | 1770 => new _StreamIterator<T>(stream); |
1771 | 1771 |
1772 /** | 1772 /** |
1773 * Wait for the next stream value to be available. | 1773 * Wait for the next stream value to be available. |
1774 * | 1774 * |
1775 * Returns a future which will complete with either `true` or `false`. | 1775 * Returns a future which will complete with either `true` or `false`. |
1776 * Completing with `true` means that another event has been received and | 1776 * Completing with `true` means that another event has been received and |
1777 * can be read as [current]. | 1777 * can be read as [current]. |
1778 * Completing with `false` means that the stream itearation is done and | 1778 * Completing with `false` means that the stream itearation is done and |
1779 * no further events will ever be available. | 1779 * no further events will ever be available. |
1780 * The future may complete with an error, if the stream produces an error, | 1780 * The future may complete with an error, if the stream produces an error, |
(...skipping 21 matching lines...) Expand all Loading... |
1802 /** | 1802 /** |
1803 * Cancels the stream iterator (and the underlying stream subscription) early. | 1803 * Cancels the stream iterator (and the underlying stream subscription) early. |
1804 * | 1804 * |
1805 * The stream iterator is automatically canceled if the [moveNext] future | 1805 * The stream iterator is automatically canceled if the [moveNext] future |
1806 * completes with either `false` or an error. | 1806 * completes with either `false` or an error. |
1807 * | 1807 * |
1808 * If you need to stop listening for values before the stream iterator is | 1808 * If you need to stop listening for values before the stream iterator is |
1809 * automatically closed, you must call [cancel] to ensure that the stream | 1809 * automatically closed, you must call [cancel] to ensure that the stream |
1810 * is properly closed. | 1810 * is properly closed. |
1811 * | 1811 * |
1812 * If [moveNext] has been called when the iterator is cancelled, | 1812 * If [moveNext] has been called when the iterator is canceled, |
1813 * its returned future will complete with `false` as value, | 1813 * its returned future will complete with `false` as value, |
1814 * as will all further calls to [moveNext]. | 1814 * as will all further calls to [moveNext]. |
1815 * | 1815 * |
1816 * Returns a future if the cancel-operation is not completed synchronously. | 1816 * Returns a future if the cancel-operation is not completed synchronously. |
1817 * Otherwise returns `null`. | 1817 * Otherwise returns `null`. |
1818 */ | 1818 */ |
1819 Future cancel(); | 1819 Future cancel(); |
1820 } | 1820 } |
1821 | 1821 |
1822 | 1822 |
1823 /** | 1823 /** |
1824 * Wraps an [_EventSink] so it exposes only the [EventSink] interface. | 1824 * Wraps an [_EventSink] so it exposes only the [EventSink] interface. |
1825 */ | 1825 */ |
1826 class _ControllerEventSinkWrapper<T> implements EventSink<T> { | 1826 class _ControllerEventSinkWrapper<T> implements EventSink<T> { |
1827 EventSink _sink; | 1827 EventSink _sink; |
1828 _ControllerEventSinkWrapper(this._sink); | 1828 _ControllerEventSinkWrapper(this._sink); |
1829 | 1829 |
1830 void add(T data) { _sink.add(data); } | 1830 void add(T data) { _sink.add(data); } |
1831 void addError(error, [StackTrace stackTrace]) { | 1831 void addError(error, [StackTrace stackTrace]) { |
1832 _sink.addError(error, stackTrace); | 1832 _sink.addError(error, stackTrace); |
1833 } | 1833 } |
1834 void close() { _sink.close(); } | 1834 void close() { _sink.close(); } |
1835 } | 1835 } |
OLD | NEW |