mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
child_process: move anonymous class to top level
Move the anonymous class out of setupChannel to clarify code. PR-URL: https://github.com/nodejs/node/pull/11147 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
1 parent
ef1731d972
commit
60fc567952
1 file changed
+19
-18
@@ -407,6 +407,24 @@ ChildProcess.prototype.unref = function() {
|
||||
if (this._handle) this._handle.unref();
|
||||
};
|
||||
|
||||
class Control extends EventEmitter {
|
||||
constructor(channel) {
|
||||
super();
|
||||
this.channel = channel;
|
||||
this.refs = 0;
|
||||
}
|
||||
ref() {
|
||||
if (++this.refs === 1) {
|
||||
this.channel.ref();
|
||||
}
|
||||
}
|
||||
unref() {
|
||||
if (--this.refs === 0) {
|
||||
this.channel.unref();
|
||||
this.emit('unref');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setupChannel(target, channel) {
|
||||
target.channel = channel;
|
||||
@@ -421,24 +439,7 @@ function setupChannel(target, channel) {
|
||||
target._handleQueue = null;
|
||||
target._pendingHandle = null;
|
||||
|
||||
const control = new class extends EventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
this.channel = channel;
|
||||
this.refs = 0;
|
||||
}
|
||||
ref() {
|
||||
if (++this.refs === 1) {
|
||||
this.channel.ref();
|
||||
}
|
||||
}
|
||||
unref() {
|
||||
if (--this.refs === 0) {
|
||||
this.channel.unref();
|
||||
this.emit('unref');
|
||||
}
|
||||
}
|
||||
}();
|
||||
const control = new Control(channel);
|
||||
|
||||
var decoder = new StringDecoder('utf8');
|
||||
var jsonBuffer = '';
|
||||
|
||||
Reference in new issue
Block a user