Skip to content

Instantly share code, notes, and snippets.

@GaetanoPiazzolla
Created April 10, 2021 17:12
Show Gist options
  • Save GaetanoPiazzolla/8308bfbcba7c9a5bc1879758e9cdc801 to your computer and use it in GitHub Desktop.
Save GaetanoPiazzolla/8308bfbcba7c9a5bc1879758e9cdc801 to your computer and use it in GitHub Desktop.
let numberOfThreads = 10;
const workerArray = [];
for (let n = 0; n < numberOfThreads; n++) {
workerArray.push(new Worker("./project_modules/worker.js"))
}
let i = 0;
const worker_array_calculus = (num,threads) => {
return new Promise((resolve, reject) => {
let workerNum = i % threads;
console.log('worker num:', workerNum)
workerArray[workerNum].on("message", result => {
resolve(result.output)
});
workerArray[workerNum].postMessage({num: num});
i++;
})
}
@GaetanoPiazzolla
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment