From 3f0643ee26b9e5d890e076835f7915003bb68d2f Mon Sep 17 00:00:00 2001 From: Claudio Rodriguez Date: Tue, 11 Apr 2017 10:39:25 +0100 Subject: [PATCH] net: refactor onSlaveClose in Server.close Refactors onSlaveClose in Server.close to be an arrow function, removes need for `self = this` and moves it down to make code more readable. PR-URL: https://github.com/nodejs/node/pull/12334 Reviewed-By: Evan Lucas Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: Yuta Hiroto --- lib/net.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/net.js b/lib/net.js index 4c1d205158f68f..40991aa6fb8a64 100644 --- a/lib/net.js +++ b/lib/net.js @@ -1517,13 +1517,6 @@ Server.prototype.getConnections = function(cb) { Server.prototype.close = function(cb) { - function onSlaveClose() { - if (--left !== 0) return; - - self._connections = 0; - self._emitCloseIfDrained(); - } - if (typeof cb === 'function') { if (!this._handle) { this.once('close', function close() { @@ -1540,8 +1533,13 @@ Server.prototype.close = function(cb) { } if (this._usingSlaves) { - var self = this; var left = this._slaves.length; + const onSlaveClose = () => { + if (--left !== 0) return; + + this._connections = 0; + this._emitCloseIfDrained(); + }; // Increment connections to be sure that, even if all sockets will be closed // during polling of slaves, `close` event will be emitted only once.