Cloning a ClonedIterator doesn't preserve HistoryReader from original source
Description
When cloning an AsyncIterator that is itself already a clone, the new clone doesn't share the same HistoryReader as the original source. This causes the newly cloned stream to:
- Not start at the expected position
- Not end at the expected position
The issue appears to stem from this code in the clone implementation:
const history = (source && (source as any)[DESTINATION]) ||
(source[DESTINATION] = new HistoryReader<T>(source) as any);
The problem seem to be that when source is itself a ClonedIterator, the code doesn't attempt to retrieve the HistoryReader from the original source iterator. Instead, it creates or uses a HistoryReader directly on the ClonedIterator, or create a new HistoryReader which can cause lost of results .