31 lines
620 B
JavaScript
31 lines
620 B
JavaScript
|
const path = require("path");
|
||
|
const rangi = require("rangi");
|
||
|
const Piscina = require("piscina");
|
||
|
|
||
|
const parser = require("./specParser").parser;
|
||
|
|
||
|
const piscina = new Piscina({
|
||
|
filename: path.resolve(__dirname, "worker.js"),
|
||
|
});
|
||
|
|
||
|
(async function () {
|
||
|
const workload = parser();
|
||
|
|
||
|
console.log(
|
||
|
rangi.red(`number of piscina workers to be allocated: ${workload.length}`)
|
||
|
);
|
||
|
|
||
|
const parallelExecutor = [];
|
||
|
|
||
|
for (let i = 0; i < workload.length; i++) {
|
||
|
parallelExecutor.push(
|
||
|
piscina.run({
|
||
|
jobId: i,
|
||
|
tasks: workload[i],
|
||
|
})
|
||
|
);
|
||
|
}
|
||
|
|
||
|
await Promise.all(parallelExecutor);
|
||
|
})();
|