Skip to content

Commit

Permalink
child_process: move anonymous class to top level
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
JacksonTian authored and jasnell committed Mar 7, 2017
1 parent c74fa1b commit 9a516bc
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,30 +415,31 @@ 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;
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 = '';
Expand Down

0 comments on commit 9a516bc

Please sign in to comment.