异步函数执行成功后,如何才能执行循环中的下一项?下面是我当前代码的sudo代码: async function myAsyncFunction(param) { // some code const myArray = ["one", "two", "three", "four"];
for(let i = 0; i
fs.readFile开始同步运行,这意味着在其中的代码块完成执行之前,循环将继续迭代。这会导致我的循环提前结束,因此,当fs.writeFile完成并尝试执行resolve(reply)时,它什么也不做,因为promise已经被末尾的reject(reply)拒绝,一旦到达数组的末尾,它就会结束循环done opening the file
file updated <----- fs.writeFile() is done saving the file to disk 如您所见,第一个循环被中断