我是 node.js 的新手,不了解有关流的文档。希望能得到一些提示。
我正在读取一个非常大的文件行,然后对于每一行我都调用一个异步网络 api。
显然,本地文件的读取速度比异步调用完成的速度要快得多:
var lineReader = require('readline').createInterface({
input: require('fs').createReadStream(program.input)
});
lineReader.on('line', function (line) {
client.execute(query, [line], function(err, result) {
// needs to pressure the line reader here
var myJSON = JSON.stringify(result);
console.log("line=%s json=%s",myJSON);
});
});
在“执行”方法中添加背压的方法是什么?