【发布时间】:2020-03-10 01:43:28
【问题描述】:
我无法让获取请求在我拥有的循环中运行。代码本质上是这样的:
function getRequest(param){
//Get request... then I save the response to a JSON file using fs.writeFile()
//...
}
function run(){
var arr = ['fee', 'foo', 'faa'];
while(I need to update this for the duration of the program){
arr.forEach((val) => {
getRequest(val);
}
}
}
get 请求不会通过,因为循环不会等待它实际请求。我已经阅读了一些使用异步函数的潜在解决方案,但无法让它们工作。有什么建议么? TIA。
【问题讨论】:
标签: javascript loops asynchronous get