Last active
July 4, 2017 12:02
-
-
Save kvasdopil/2a453b690a916459d2ffcef1e3b6625b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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