Pause does not work
See original GitHub issueWhy is this important? MongoDB is in many cases the standard to node when it comes to Databases. However if events are emitted faster than Mongoose can handle them, It can result in duplication and or index errors and possibly more
Attempts at solutions and work arounds
- Pausing the Stream Directly inside of the “record” event
stream = fs.createReadStream(filepath);
csvstream = csv.fromStream(stream).on("record", function(data){
stream.pause();
console.log("shouldn't see this more than once");
})
stream.pause() doesn’t seem to do anything 2) Going into old mode, then pausing directly
stream = fs.createReadStream(filepath);
stream.pause();
csvstream = csv.fromStream(stream).on("record", function(data){
stream.pause();
console.log("shouldn't see this more than once");
})
stream.resume();
stream.pause() doesn’t seem to do anything 3) using pause method of the Parser_Stream https://github.com/C2FO/fast-csv/blob/master/lib/parser_stream.js#L156
stream = fs.createReadStream(filepath);
csvstream = csv.fromStream(stream).on("record", function(data){
csvstream.pause();
console.log("shouldn't see this more than once");
})
csvstream.pause() doesn’t seem to do anything 4) combining both https://github.com/C2FO/fast-csv/blob/master/lib/parser_stream.js#L156
stream = fs.createReadStream(filepath);
stream.pause();
csvstream = csv.fromStream(stream).on("record", function(data){
stream.pause();
csvstream.pause();
console.log("shouldn't see this more than once");
})
stream.resume();
callback doesn’t seem to do anything 5) Using csvstream to resume
stream = fs.createReadStream(filepath);
stream.pause();
csvstream = csv.fromStream(stream).on("record", function(data){
stream.pause();
csvstream.pause();
console.log("shouldn't see this more than once");
})
csvstream.resume();
Process Doesn’t start https://github.com/C2FO/fast-csv/blob/master/lib/parser_stream.js#L163 6) Attempt to see if csvstream.pause() even matters (which it doesn’t)
stream = fs.createReadStream(filepath);
stream.pause();
csvstream = csv.fromStream(stream).on("record", function(data){
stream.pause();
console.log("shouldn't see this");
})
csvstream.pause();
stream.resume();
Doesn’t work 7) Using from path
csvstream = csv.fromPath(filepath).on("record", function(data){
csvstream.pause();
console.log("shouldn't see this more than once");
})
Doesn’t work 8) Checking if from path at least prevents it
csvstream = csv.fromPath(filepath).on("record", function(data){
console.log("shouldn't see this");
})
csvstream.pause();
Doesn’t work
Issue Analytics
- State:
- Created 9 years ago
- Reactions:2
- Comments:10 (3 by maintainers)
Top GitHub Comments
Can you point me in the right direction? I’m having some bugs with pausing in
2.4.1
whereend
is called while my callbacks are still working on processing from thedata
callbacks.I’m having the same issue as @Xeoncross .
My
end
callback gets fired before my last row has stopped processing.Here’s how my code is laid out: