Chained transformations make empty iterators un-lazy
Closed this issue · 0 comments
rubensworks commented
When transforming an empty lazy stream, the final stream becomes un-lazy.
This makes it so that the end-event can be emitted before any listeners can be attached.
Minimal reproducible example:
(async function() {
// Create a lazy array it
const arrayIt = new ArrayIterator([], { autoStart: false });
// Transform it twice (both lazy)
const transformedIt1 = arrayIt.transform({
map: () => 1,
autoStart: false,
});
const transformedIt2 = transformedIt1.transform({
map: () => 1,
autoStart: false,
});
console.log('WAITING...');
setTimeout(() => {
console.log('ATTACHING LISTENERS...');
// The listeners below are never called
transformedIt2.on('data', () => console.log('DATA'));
transformedIt2.on('end', () => console.log('ENDED'));
}, 1000);
})();