mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 14:52:19 +00:00

This switches all `util.inherits()` calls to use `Object.setPrototypeOf()` instead. In fact, `util.inherits()` is mainly a small wrapper around exactly this function while adding the `_super` property on the object as well. Refs: #24395 PR-URL: https://github.com/nodejs/node/pull/24755 Refs: https://github.com/nodejs/node/issues/24395 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
'use strict';
|
|
const EventEmitter = require('events');
|
|
|
|
module.exports = Worker;
|
|
|
|
// Common Worker implementation shared between the cluster master and workers.
|
|
function Worker(options) {
|
|
if (!(this instanceof Worker))
|
|
return new Worker(options);
|
|
|
|
EventEmitter.call(this);
|
|
|
|
if (options === null || typeof options !== 'object')
|
|
options = {};
|
|
|
|
this.exitedAfterDisconnect = undefined;
|
|
|
|
this.state = options.state || 'none';
|
|
this.id = options.id | 0;
|
|
|
|
if (options.process) {
|
|
this.process = options.process;
|
|
this.process.on('error', (code, signal) =>
|
|
this.emit('error', code, signal)
|
|
);
|
|
this.process.on('message', (message, handle) =>
|
|
this.emit('message', message, handle)
|
|
);
|
|
}
|
|
}
|
|
|
|
Object.setPrototypeOf(Worker.prototype, EventEmitter.prototype);
|
|
|
|
Worker.prototype.kill = function() {
|
|
this.destroy.apply(this, arguments);
|
|
};
|
|
|
|
Worker.prototype.send = function() {
|
|
return this.process.send.apply(this.process, arguments);
|
|
};
|
|
|
|
Worker.prototype.isDead = function() {
|
|
return this.process.exitCode != null || this.process.signalCode != null;
|
|
};
|
|
|
|
Worker.prototype.isConnected = function() {
|
|
return this.process.connected;
|
|
};
|