| 582 | } |
| 583 | |
| 584 | private async serialNext(): Promise<IteratorResult<T>> { |
| 585 | // TODO(soergel): consider tradeoffs of reading in parallel, eg. |
| 586 | // collecting next() promises in an Array and then waiting for |
| 587 | // Promise.all() of those. Benefit: pseudo-parallel execution. Drawback: |
| 588 | // maybe delayed GC. |
| 589 | while (this.count++ < this.maxCount) { |
| 590 | const skipped = await this.upstream.next(); |
| 591 | // short-circuit if upstream is already empty |
| 592 | if (skipped.done) { |
| 593 | return skipped; |
| 594 | } |
| 595 | tf.dispose(skipped.value as {}); |
| 596 | } |
| 597 | return this.upstream.next(); |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | class TakeIterator<T> extends LazyIterator<T> { |