I have to call a 3rd party API repeatedly using bluebird Promise.map API in nodeJS. But the problem is the API supports only 20 requests per second. I wanted understand how this can be implemented. This is what I tried. But it gives me an infinite loop.
let count = 0;
setInterval(() => count = 0, 1000); //reset the counter to 0 once in every second
await Promise.map(data, datum => {
count++;
while(count>=20){ //create an infinite loop if the count is more than 20 to wait till the count is reset.
} //The loop exits once the count value is reset to 0 by setIntercal
await axios({
url: process.env.MDNFS_URL,
body: datum,
method: 'POST'
})
}, {concurrency:10})