async function readFiles(files) {
for(const file of files) {
await readFile(file);
}
};
async function* readFiles(files) {
for(const file of files) {
yield await readFile(file);
}
}
function readFiles(files) {
let p = Promise.resolve()
files.forEach(f => {
p = p.then(() => readFile(f))
})
return p
}
Or more succinct,
function readFiles(files) {
return files.reduce((p, f) => {
return p.then(() => readFile(f))
}, Promise.resolve())
}