而循环不等待等待
我知道有很多这样的问题,但是我找不到适合我的情况的问题。我正在循环循环拨打API,只是不想快速开火来超时我的电话。 While循环似乎并没有等待通话完成。
while(it < array.length){
await apiFunction(array[it]);
console.log(it);
it++
}
功能
async apiFunction(array){
try{
(async () => {
const result = await api.doStuff(array);
console.dir(result);
}
} catch (e) {
stuff;
}
}
而且我也尝试添加返回的
(结果),但这并没有更改我的控制台输出的任何内容,
0
1
result
result
我该如何才能使way循环等待直到API调用完成?所以我的控制台看起来像
0
result
1
result
I know there's a ton of these questions but I haven't been able to find one that fits my case. I'm making api calls in a while loop and just don't want to time out my calls by rapid firing them. The while loop doesn't seem to be waiting for the call to finish.
while(it < array.length){
await apiFunction(array[it]);
console.log(it);
it++
}
and the function
async apiFunction(array){
try{
(async () => {
const result = await api.doStuff(array);
console.dir(result);
}
} catch (e) {
stuff;
}
}
I've also tried adding a return(result) but that didn't change anything
My console output is
0
1
result
result
How can I get the while loop to wait until the api call is done? so my console looks like
0
result
1
result
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我有太多的异步性。刚刚从呼吸中删除异步
I had too many layers of asynchronicity going I guess. Just removed the async from inside the apiFunction