费率限制nodejs bluebird Promise.map
我必须使用bluebird promise.map api在nodejs中反复致电第三方API。但是问题是API每秒仅支持20个请求。我想了解如何实现这一点。这就是我尝试的。但这给了我一个无限的循环。
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})
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})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我省略了蓝鸟,但是您几乎可以对此做完全相同的事情。
I omitted bluebird, but you could pretty much do the exact same thing with it.