From 9a516bcedb500bf5e0a0aa65d33451d4f580395d Mon Sep 17 00:00:00 2001 From: Jackson Tian Date: Sat, 4 Feb 2017 00:23:10 +0800 Subject: [PATCH] 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 Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: Anna Henningsen --- lib/internal/child_process.js | 37 ++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index 871fdc0cf18832..a03b6cefd5c69b 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -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 = '';