diff --git a/lib/workers/child-browser.js b/lib/workers/child-browser.js index b824662c..fe3e8e5e 100644 --- a/lib/workers/child-browser.js +++ b/lib/workers/child-browser.js @@ -11,9 +11,10 @@ const EventEmitter = require('events'); const util = require('../utils/util'); /** - * Represents a worker. + * Represents a child process. * @alias module:workers.Child * @constructor + * @ignore * @param {String} file * @param {Object} env */ @@ -30,7 +31,7 @@ function Child(file, env) { util.inherits(Child, EventEmitter); /** - * Test whether worker support is available. + * Test whether child process support is available. * @returns {Boolean} */ @@ -39,7 +40,7 @@ Child.hasSupport = function hasSupport() { }; /** - * Initialize worker. Bind to events. + * Initialize child process. Bind to events. * @private */ @@ -69,7 +70,7 @@ Child.prototype.init = function init(file, env) { }; /** - * Send data to worker. + * Send data to child process. * @param {Buffer} data * @returns {Boolean} */ @@ -85,7 +86,7 @@ Child.prototype.write = function write(data) { }; /** - * Destroy the worker. + * Destroy the child process. */ Child.prototype.destroy = function destroy() { diff --git a/lib/workers/child.js b/lib/workers/child.js index a0bd5c57..e7f65b8e 100644 --- a/lib/workers/child.js +++ b/lib/workers/child.js @@ -15,7 +15,7 @@ const children = new Set(); let exitBound = false; /** - * Represents a worker. + * Represents a child process. * @alias module:workers.Child * @constructor * @param {String} file @@ -37,7 +37,7 @@ function Child(file, env) { util.inherits(Child, EventEmitter); /** - * Test whether worker support is available. + * Test whether child process support is available. * @returns {Boolean} */ @@ -46,7 +46,7 @@ Child.hasSupport = function hasSupport() { }; /** - * Initialize worker (node.js). + * Initialize child process (node.js). * @private */ @@ -95,7 +95,7 @@ Child.prototype.init = function init(file, env) { }; /** - * Send data to worker. + * Send data to child process. * @param {Buffer} data * @returns {Boolean} */ @@ -105,7 +105,7 @@ Child.prototype.write = function write(data) { }; /** - * Destroy the worker. + * Destroy the child process. */ Child.prototype.destroy = function destroy() { diff --git a/lib/workers/master.js b/lib/workers/master.js index 6bd68e4a..65b4d550 100644 --- a/lib/workers/master.js +++ b/lib/workers/master.js @@ -51,6 +51,15 @@ Master.prototype.init = function init() { this.parser.feed(data); }); + this.parent.on('error', (data) => { + this.emit('error', err); + }); + + this.parent.on('exception', (err) => { + this.send(new packets.ErrorPacket(err)); + setTimeout(() => this.destroy(), 1000); + }); + this.parser.on('error', (err) => { this.emit('error', err); }); @@ -58,11 +67,6 @@ Master.prototype.init = function init() { this.parser.on('packet', (packet) => { this.emit('packet', packet); }); - - this.parent.on('exception', (err) => { - this.send(new packets.ErrorPacket(err)); - setTimeout(() => this.destroy(), 1000); - }); }; /** diff --git a/lib/workers/parent-browser.js b/lib/workers/parent-browser.js index 32d1613e..5c811135 100644 --- a/lib/workers/parent-browser.js +++ b/lib/workers/parent-browser.js @@ -14,6 +14,7 @@ const util = require('../utils/util'); * Represents the parent process. * @alias module:workers.Parent * @constructor + * @ignore */ function Parent() { @@ -53,7 +54,7 @@ Parent.prototype.init = function init() { }; /** - * Send data to worker. + * Send data to parent process. * @param {Buffer} data * @returns {Boolean} */ @@ -69,7 +70,7 @@ Parent.prototype.write = function write(data) { }; /** - * Destroy the worker. + * Destroy the parent process. */ Parent.prototype.destroy = function destroy() { diff --git a/lib/workers/parent.js b/lib/workers/parent.js index 1a0f5886..77dc6ed8 100644 --- a/lib/workers/parent.js +++ b/lib/workers/parent.js @@ -47,7 +47,7 @@ Parent.prototype.init = function init() { }; /** - * Send data to worker. + * Send data to parent process. * @param {Buffer} data * @returns {Boolean} */ @@ -57,7 +57,7 @@ Parent.prototype.write = function write(data) { }; /** - * Destroy the worker. + * Destroy the parent process. */ Parent.prototype.destroy = function destroy() {