[英]Nested Async/Await function
It's easier just to look at the code: 只需查看代码就更容易了:
async function addFiles(dir,tree) {
return (await readDir(dir))
.map(name => {await readDir(dir); return name;}) // error here
}
This code returns an error on line 3, saying there's an unexpected token near readDir
. 此代码在第3行返回错误,表示
readDir
附近有一个意外的令牌。 I don't understand why this won't work. 我不明白为什么这不起作用。
It turns out, I forgot to declare my arrow function as async. 事实证明,我忘了将我的箭头函数声明为异步。
the revised code is 修改后的代码是
async function addFiles(dir,tree) {
return (await readDir(dir))
.map(async name => {await readDir(dir); return name;}) // error here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.