(path, size = 0, strategy = 'roundrobin')
| 4 | |
| 5 | module.exports = class RpcWorkerPool { |
| 6 | constructor(path, size = 0, strategy = 'roundrobin') { |
| 7 | if (size === 0) this.size = CORES; // <1> |
| 8 | else if (size < 0) this.size = Math.max(CORES + size, 1); |
| 9 | else this.size = size; |
| 10 | |
| 11 | if (!STRATEGIES.has(strategy)) throw new TypeError('invalid strategy'); |
| 12 | this.strategy = strategy; // <2> |
| 13 | this.rr_index = -1; |
| 14 | |
| 15 | this.next_command_id = 0; |
| 16 | this.workers = []; // <3> |
| 17 | for (let i = 0; i < this.size; i++) { |
| 18 | const worker = new Worker(path); |
| 19 | this.workers.push({ worker, in_flight_commands: new Map() }); // <4> |
| 20 | worker.on('message', (msg) => { |
| 21 | this.onMessageHandler(msg, i); |
| 22 | }); |
| 23 | } |
| 24 | } |
| 25 | // THIS LINE SHOULD NOT APPEAR IN PRINT |
| 26 | onMessageHandler(msg, worker_id) { |
| 27 | const worker = this.workers[worker_id]; |
nothing calls this directly
no test coverage detected