I want to verify that I'm awaiting fs.promises correctly.
I have entries in a map called res that I want to write to a file.
I know for sure that this would await them:
for(let [path, content] of res.entries()) {
await fs.promises.writeFile(path, content)
}
But this is inefficient so I'm curious if this does it:
let promises = []
for(let [path, context] of res.entries()) {
promises.push( fs.promises.writeFile(path, content) );
}
await Promise.all(promises)
The reason why I'm not sure if the second example works is because writeFile is simply an async function, so I'm not sure if the await is actually awaiting anything.
The other options would be to do something fancy to make a line like this possible Promise(fs.writeFile(...)) (which isn't possible as is) to await it.