【发布时间】:2020-01-31 01:15:11
【问题描述】:
我正在处理不支持 ES6 标准的旧项目。
为了便于理解,我将编写我想要达到的代码,请在不使用 async/await 对的情况下翻译以下代码。
async function doSomeCalls(arrayWithNeededCalls){
for(let i = 0; i < arrayWithNeededCalls.length; i++){
await makeSomeCall(arrayWithNeededCalls[i]);
console.log("Call: ", i, " Completed going to next one");
}
}
我尝试使用
Promise.all()
但它不会在运行第二个承诺之前等待一个承诺完成。
【问题讨论】:
-
嗨,你能补充一下你到目前为止尝试过的东西吗?这不是编码服务,请尝试解决您的问题,如果您遇到问题,我们可以为您提供帮助。
-
arrayWithNeededCalls 映射到 Promises 并使用
Promise.all并行或将 arrayWithNeededCalls 减少为一个 Promise -
你好@Nicolas,这段代码几乎是我想要实现的所有目标,但对于遗留项目来说是旧的方式。
-
难道没有可以将新功能转换为旧标准的工具吗?通天塔什么的?
标签: javascript asynchronous promise