I've tried this simple code using node-lazy:
var productStream = function (readstream) {
return new Lazy(readstream)
.lines.forEach(function (line) {
console.log(count++);
if (count > 10) {
console.log("Should stop");
readstream.pause();
}
return normalizeAttributes(JSON.parse(line.toString().slice(0, -1)));
})
}
console.log(productStream(fs.createReadStream(datafile)).take(5));
Lazy does not stop after the tenth line, it sweeps through the whole file. Can anyone explain why? I've seen the answer here, but I'm curious if there's a bug in the library or there's something else I need to do.