--
This commit is contained in:
parent
4516907c76
commit
aead4d7624
14 changed files with 3268 additions and 0 deletions
30
parallel.js
Normal file
30
parallel.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* @author Jose Stovall | oitsjustjose
|
||||
* @description A file for creating an array of random prime integers, similar to Homework 3
|
||||
*/
|
||||
|
||||
const Threads = require('webworker-threads');
|
||||
const path = require("path");
|
||||
|
||||
const getPrimes = (arrSize) => {
|
||||
let threads = Threads.createPool(arrSize);
|
||||
|
||||
let primes = [];
|
||||
|
||||
threads.load(path.join(__dirname, "primefinder.js"), (err, data) => {
|
||||
if (err) {
|
||||
console.log(`ERROR: ${err}`);
|
||||
} else {
|
||||
primes.push(data);
|
||||
|
||||
// Quit once we've gotten the right number of primes!
|
||||
if (primes.length == arrSize) {
|
||||
threads.destroy();
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
"getPrimes": getPrimes
|
||||
};
|
||||
Loading…
Reference in a new issue