-
-
Save Olegas/f181b05700f1d84459b10135e0b715ca 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() { | |
var runningWorkers = 0; | |
function continuationHandler() { | |
runningWorkers--; | |
loadWorkers(); | |
} | |
function pickItem() { | |
const file = files.shift(); | |
if (file) { | |
runningWorkers++; | |
// continue in any case | |
worker(file).then(continuationHandler, continuationHandler); | |
} | |
} | |
function loadWorkers() { | |
do { | |
pickItem(); | |
} while(runningWorkers < limit) | |
} | |
loadWorkers(); | |
} | |
async function worker(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