只看代码更容易:
async function addFiles(dir,tree) {
return (await readDir(dir))
.map(name => {await readDir(dir); return name;}) // error here
}
此代码在第 3 行返回一个错误,表示 readDir
附近有一个意外标记。我不明白为什么这行不通。
最佳答案
事实证明,我忘了将我的箭头函数声明为异步。
修改后的代码是
async function addFiles(dir,tree) {
return (await readDir(dir))
.map(async name => {await readDir(dir); return name;}) // error here
}
关于javascript - 嵌套异步/等待函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36992095/