diff --git a/lib/workers/master.js b/lib/workers/master.js index a003f5f0..b48c5174 100644 --- a/lib/workers/master.js +++ b/lib/workers/master.js @@ -146,9 +146,6 @@ Master.prototype.listen = function listen() { this.listening = true; - util.log = this.log.bind(this); - util.error = util.log; - this.on('error', (err) => { this.send(new packets.ErrorPacket(err)); }); @@ -177,7 +174,7 @@ Master.prototype.handlePacket = function handlePacket(packet) { break; case packets.types.EVENT: this.emit('event', packet.items); - this.emit.apply(this, packet.items); + this.emit(...packet.items); break; case packets.types.ERROR: this.emit('error', packet.error); diff --git a/lib/workers/worker.js b/lib/workers/worker.js index 92fdc33f..197a7b1c 100644 --- a/lib/workers/worker.js +++ b/lib/workers/worker.js @@ -8,6 +8,10 @@ 'use strict'; const Master = require('./master'); +const util = require('../utils/util'); const server = new Master(); +util.log = server.log.bind(server); +util.error = util.log; + server.listen(); diff --git a/lib/workers/workerpool.js b/lib/workers/workerpool.js index d888ee08..5038acb9 100644 --- a/lib/workers/workerpool.js +++ b/lib/workers/workerpool.js @@ -124,7 +124,7 @@ WorkerPool.prototype.spawn = function spawn(id) { child.on('event', (items) => { this.emit('event', items, child); - this.emit.apply(this, items); + this.emit(...items); }); child.on('log', (text) => { @@ -186,11 +186,12 @@ WorkerPool.prototype.destroy = function destroy() { */ WorkerPool.prototype.execute = function execute(packet, timeout) { - let result, child; + let child; if (!this.enabled || !Child.hasSupport()) { return new Promise((resolve, reject) => { setImmediate(() => { + let result; try { result = jobs.handle(packet); } catch (e) { @@ -447,8 +448,8 @@ Worker.prototype.listen = function listen() { Worker.prototype.handlePacket = function handlePacket(packet) { switch (packet.cmd) { case packets.types.EVENT: - this.emit.apply(this, packet.items); this.emit('event', packet.items); + this.emit(...packet.items); break; case packets.types.LOG: this.emit('log', packet.text);