Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = '';
Expand Down