I have 1000 records that need to hit an API endpoint that is rate limited. I want to make it so that there is only 5 calls on the URL at any given time so that I am not making 1000 requests simultaneously. How can I do this? I have the following:
var Promise = require("bluebird");
var geocoder = Promise.promisifyAll(require('geocoder'));
var fs = require('fs');
var async = require('async');
var parse = require('csv-parse/lib/sync');
var inputFile = './myaddresses.txt'
var file = fs.readFileSync(inputFile, "utf8");
var records = parse(file, {columns: true});
var promises = [];
for(var i = 0; i < records.length; i++) {
var placeName = records[i]['Place Name'];
promises.push(geocoder.geocodeAsync(placeName));
}
Promises.all(promises).then(function(result) {
result.forEach(function(geocodeResponse) {
console.log(geocodeResponse);
})
}