Brief Intro
I am developing server side application in NodeJS which include one module which read data from csv file and perform some task.
In CSV file data could be in Millions lines but at the same time I am having limited memory available.
To perform a task I am using kue (creating a job per line)
currently I am creating jobs as soon as CSV reader give me dataand kue is keeping that job in memory and will not leave until it finish (So till the CSV reader finish reading file there is millions of job exists in memory).
So as a solution What I want to do is I read first few hundreds lines create jobs let wait till it finish
then read another hundreds.
Here waiting is more important I can not use any module which allow me to read file line by line because in that case it will keep returning me liens and I will keep creating jobs.
I want control on reader such that when I get desired hundreds (ex 100) I will wait till all 100 will finish then ask reader to return next hundreds (ex next 100).
Conclusion
I want to know how I can read few lines from a csv file then process it and then read remaining (Same is pagination).
Code will look something like below
const smartReader = required('snartReader');
smartReader.read(100,(data,next) => {
performJobs(data); // wait until it finish then
next(); // it will read next 100 });
Declaration
I am not an experienced person in NodeJS and this is my first application.