【发布时间】:2018-03-15 04:06:00
【问题描述】:
使用 nodejs,我从 api 获取数据。该 api 有限制率,所以我试图做一些从标头中获得限制的东西,比较最大和当前请求,如果它们相等,那么不要在一段时间内发送请求,你明白了。
我在考虑if 语句,但条件中的变量是在 if 语句本身内部的请求中声明的,例如:
if (curr > max - 2){
res.send("limit reached");
return;
}
else{
//use request module to get headers from the api and split header to get
//max and current count of request then declare them to curr and max
//so when someone else call the same request it compare the old vars
// if the statement is false it do the call and get the new vars
//if it is true it make a delay before next request
}
我知道这很愚蠢,我什至吸收了基本逻辑,我不知道.. 如果有更好的方法可以有人指出它。谢谢
【问题讨论】:
标签: node.js variables if-statement scope