workers: minor.
This commit is contained in:
parent
27c60ce76e
commit
f591e577f1
@ -11,9 +11,10 @@ const EventEmitter = require('events');
|
|||||||
const util = require('../utils/util');
|
const util = require('../utils/util');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a worker.
|
* Represents a child process.
|
||||||
* @alias module:workers.Child
|
* @alias module:workers.Child
|
||||||
* @constructor
|
* @constructor
|
||||||
|
* @ignore
|
||||||
* @param {String} file
|
* @param {String} file
|
||||||
* @param {Object} env
|
* @param {Object} env
|
||||||
*/
|
*/
|
||||||
@ -30,7 +31,7 @@ function Child(file, env) {
|
|||||||
util.inherits(Child, EventEmitter);
|
util.inherits(Child, EventEmitter);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test whether worker support is available.
|
* Test whether child process support is available.
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -39,7 +40,7 @@ Child.hasSupport = function hasSupport() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize worker. Bind to events.
|
* Initialize child process. Bind to events.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -69,7 +70,7 @@ Child.prototype.init = function init(file, env) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send data to worker.
|
* Send data to child process.
|
||||||
* @param {Buffer} data
|
* @param {Buffer} data
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
@ -85,7 +86,7 @@ Child.prototype.write = function write(data) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy the worker.
|
* Destroy the child process.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Child.prototype.destroy = function destroy() {
|
Child.prototype.destroy = function destroy() {
|
||||||
|
|||||||
@ -15,7 +15,7 @@ const children = new Set();
|
|||||||
let exitBound = false;
|
let exitBound = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a worker.
|
* Represents a child process.
|
||||||
* @alias module:workers.Child
|
* @alias module:workers.Child
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {String} file
|
* @param {String} file
|
||||||
@ -37,7 +37,7 @@ function Child(file, env) {
|
|||||||
util.inherits(Child, EventEmitter);
|
util.inherits(Child, EventEmitter);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test whether worker support is available.
|
* Test whether child process support is available.
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ Child.hasSupport = function hasSupport() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize worker (node.js).
|
* Initialize child process (node.js).
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ Child.prototype.init = function init(file, env) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send data to worker.
|
* Send data to child process.
|
||||||
* @param {Buffer} data
|
* @param {Buffer} data
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
@ -105,7 +105,7 @@ Child.prototype.write = function write(data) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy the worker.
|
* Destroy the child process.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Child.prototype.destroy = function destroy() {
|
Child.prototype.destroy = function destroy() {
|
||||||
|
|||||||
@ -51,6 +51,15 @@ Master.prototype.init = function init() {
|
|||||||
this.parser.feed(data);
|
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.parser.on('error', (err) => {
|
||||||
this.emit('error', err);
|
this.emit('error', err);
|
||||||
});
|
});
|
||||||
@ -58,11 +67,6 @@ Master.prototype.init = function init() {
|
|||||||
this.parser.on('packet', (packet) => {
|
this.parser.on('packet', (packet) => {
|
||||||
this.emit('packet', packet);
|
this.emit('packet', packet);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.parent.on('exception', (err) => {
|
|
||||||
this.send(new packets.ErrorPacket(err));
|
|
||||||
setTimeout(() => this.destroy(), 1000);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -14,6 +14,7 @@ const util = require('../utils/util');
|
|||||||
* Represents the parent process.
|
* Represents the parent process.
|
||||||
* @alias module:workers.Parent
|
* @alias module:workers.Parent
|
||||||
* @constructor
|
* @constructor
|
||||||
|
* @ignore
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function Parent() {
|
function Parent() {
|
||||||
@ -53,7 +54,7 @@ Parent.prototype.init = function init() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send data to worker.
|
* Send data to parent process.
|
||||||
* @param {Buffer} data
|
* @param {Buffer} data
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
@ -69,7 +70,7 @@ Parent.prototype.write = function write(data) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy the worker.
|
* Destroy the parent process.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Parent.prototype.destroy = function destroy() {
|
Parent.prototype.destroy = function destroy() {
|
||||||
|
|||||||
@ -47,7 +47,7 @@ Parent.prototype.init = function init() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send data to worker.
|
* Send data to parent process.
|
||||||
* @param {Buffer} data
|
* @param {Buffer} data
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
@ -57,7 +57,7 @@ Parent.prototype.write = function write(data) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy the worker.
|
* Destroy the parent process.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Parent.prototype.destroy = function destroy() {
|
Parent.prototype.destroy = function destroy() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user