Skip to content

Commit 60fc567

Browse files
JacksonTianitaloacasas
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 <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent ef1731d commit 60fc567

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

lib/internal/child_process.js

+19-18
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,24 @@ ChildProcess.prototype.unref = function() {
407407
if (this._handle) this._handle.unref();
408408
};
409409

410+
class Control extends EventEmitter {
411+
constructor(channel) {
412+
super();
413+
this.channel = channel;
414+
this.refs = 0;
415+
}
416+
ref() {
417+
if (++this.refs === 1) {
418+
this.channel.ref();
419+
}
420+
}
421+
unref() {
422+
if (--this.refs === 0) {
423+
this.channel.unref();
424+
this.emit('unref');
425+
}
426+
}
427+
}
410428

411429
function setupChannel(target, channel) {
412430
target.channel = channel;
@@ -421,24 +439,7 @@ function setupChannel(target, 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)