Safe way to run multiple async functions in parallel?

Viewed 1184

I'm writing some code to scan a directory and it occurred to me this may not be the best idea:

files.forEach(async fileName => {
  stat = await lstat(fileName);
});

as I'm going to fire off an lstat for every single file in a directory at the same time. Does anyone know of a "clean" way to do this? I'm thinking a lib that maintains a queue and drains it.

I know some "old" async libraries do this, but I don't know of anything that do it with native async/await calls

2 Answers
Related