Asynchronous map function that await's returns Promise instead of value

前端 未结 2 1247
陌清茗
陌清茗 2021-02-05 17:01

I have this code

async function addFiles(dir,tree) {
  return (await readDir(dir))
    .map(async (name) => {await readDir(dir); return name;})
}
2条回答
  •  花落未央
    2021-02-05 18:04

    try

    async function addFiles(dir,tree) {
      const files = await readDir(dir)
      await Promise.all(files.map(async (name) => {await readDir(dir); return name;})
    }
    

提交回复
热议问题