NodeJs csv模块 – 暂停和恢复

我正在使用nodeJs csv模块来parsing一个10000logging大csv和每个logging即.on('logging',func),我必须执行一个耗时的逻辑。 但节点不会等到我完成。 我该如何处理? 文件谈到http://www.adaltas.com/projects/node-csv/暂停()和简历()。 但是我在哪里使用它?

var csv = require('csv'); var fs = require('fs'); csv() .from.stream(fs.createReadStream(__dirname+'/sample.in')) .to.path(__dirname+'/sample.out') .transform( function(row){ row.unshift(row.pop()); return row; }) .on('record', function(row,index){ //Time consuming logic goes here }) .on('end', function(count){ console.log('Number of lines: '+count); }) .on('error', function(error){ console.log(error.message); }); 

我终于得到了这个工作。 感谢node-csv开发人员

 //Read through the csv file one row at a time csv() .from(__dirname+'data.csv', { columns: true }) .transform(function(row, index, next){ setTimeout(function(){ console.log(row); next() }, 3000); //replace setTimeout with any fn and call next() in the callback }, {parallel: 1}) .on("end", function (count) { var finalcount = count; var logtext = 'SUMMARY: Total count: ' + finalcount + '\n' + 'Error count:' + errorcount + "("+errorArray+")" + '\n' + 'Success count:' + successcount; fs.appendFile(config.logfilename, '\n'+ logtext, function (err) { console.log(logtext); }); console.log("done", count); });