Skip to content

Commit 4179c70

Browse files
JacksonTianMylesBorins
authored andcommitted
child_process: move anonymous class to top level
Move the anonymous class out of setupChannel to clarify code. PR-URL: #11147 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent b38d8d6 commit 4179c70

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

lib/internal/child_process.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -415,30 +415,31 @@ ChildProcess.prototype.unref = function() {
415415
if (this._handle) this._handle.unref();
416416
};
417417

418+
class Control extends EventEmitter {
419+
constructor(channel) {
420+
super();
421+
this.channel = channel;
422+
this.refs = 0;
423+
}
424+
ref() {
425+
if (++this.refs === 1) {
426+
this.channel.ref();
427+
}
428+
}
429+
unref() {
430+
if (--this.refs === 0) {
431+
this.channel.unref();
432+
this.emit('unref');
433+
}
434+
}
435+
}
418436

419437
function setupChannel(target, channel) {
420438
target._channel = channel;
421439
target._handleQueue = null;
422440
target._pendingHandle = null;
423441

424-
const control = new class extends EventEmitter {
425-
constructor() {
426-
super();
427-
this.channel = channel;
428-
this.refs = 0;
429-
}
430-
ref() {
431-
if (++this.refs === 1) {
432-
this.channel.ref();
433-
}
434-
}
435-
unref() {
436-
if (--this.refs === 0) {
437-
this.channel.unref();
438-
this.emit('unref');
439-
}
440-
}
441-
}();
442+
const control = new Control(channel);
442443

443444
var decoder = new StringDecoder('utf8');
444445
var jsonBuffer = '';

0 commit comments

Comments
 (0)