| 863 | protected abstract pump(): Promise<boolean>; |
| 864 | |
| 865 | async serialNext(): Promise<IteratorResult<T>> { |
| 866 | // Fetch so that the queue contains at least one item if possible. |
| 867 | // If the upstream source is exhausted, AND there are no items left in |
| 868 | // the output queue, then this stream is also exhausted. |
| 869 | while (this.outputQueue.length() === 0) { |
| 870 | // TODO(soergel): consider parallel reads. |
| 871 | if (!await this.pump()) { |
| 872 | return {value: null, done: true}; |
| 873 | } |
| 874 | } |
| 875 | return {value: this.outputQueue.shift(), done: false}; |
| 876 | } |
| 877 | } |
| 878 | class FlatmapIterator<I, O> extends OneToManyIterator<O> { |
| 879 | constructor( |