Skip to content

Instantly share code, notes, and snippets.

@kvasdopil
Last active July 4, 2017 12:02
Show Gist options
  • Save kvasdopil/2a453b690a916459d2ffcef1e3b6625b to your computer and use it in GitHub Desktop.
Save kvasdopil/2a453b690a916459d2ffcef1e3b6625b to your computer and use it in GitHub Desktop.
const files = [/* file names here */];
const limit = 100;
async function main() {
const workers = [];
while(workers.length <= limit) {
const w = worker(files);
workers.push(w);
}
await Promise.all(workers);
}
async function worker(files) {
while(files.length) {
const file = files.shift();
await processFile(file);
}
}
async function processFile(file) {
return new Promise(done => {
// process file and call done at the end
// alternatively use async/await file functions
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment