Skip to content

Instantly share code, notes, and snippets.

@wadez
Created June 13, 2021 17:33
Show Gist options
  • Save wadez/047d90c01e96295f7da3ecc023b1f9be to your computer and use it in GitHub Desktop.
Save wadez/047d90c01e96295f7da3ecc023b1f9be to your computer and use it in GitHub Desktop.
const pool = [0,1,2,3] // 4 threads available
while (pool.length && queue.length) {
var id = pool.pop();
promises.push(new Promise((...) => {
...
worker.on("exit", (...) => {
pool.push(id)
resolve()
})
...
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment