-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.transform() async callback? #24
Comments
You could call We do something similar but we do this in the For example to reduce the total IO as a large number of requests could build up. //up above
var users = [],
FIND_EVERY = 1000;
.on("record", function(data){
users.push(data);
if(users.length === FIND_EVERY){
csvStream.pause(); //no more record events will be produced until resume is called
doSomethingWithUsers(users, function(err, res){
if(err){
console.log(err.stack);
}else{
csvStream.resume(); //ok continue parsing
}
});
}
}); Hope this helps. |
I imagine you can use Promises to accomplish this without pausing. |
Thanks for highlighting the usage of pause. I have to load 400M of CSV data to a database. This solution seems reliable. Initially I used a Wouldn't the ideal solution be to use It's possible I'm missing something obvious here but that would seem the ideal solution for me as you don't have to muck with |
Im not sure I understand can you please provide an example of what you are trying to do Thanks! -Doug |
@doug-martin Sure. I would expect the following to work more or less: ...
var stream = csv.fromPath(path, {
headers: true
}).
pipe(function(data, _, next) {
// write to db now (async, resumes on next)
db.getOrCreate(data.id, next);
}); Obviously this won't work in the current version. I understand I could add Allowing piping like this would make it possible to skip the pause/resume business. |
I agree with bebraw, at a minimum pass a next function to on('record', function(data,next){ }) for async support, and deprecate the pause/resume which is non-standard. |
There is now async support for -Doug |
Is it possible to do an async operation in the transform method?
The text was updated successfully, but these errors were encountered: