Skip to content

Commit 1bd07ac

Browse files
claudiorodriguezMylesBorins
authored andcommitted
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: #12334 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
1 parent bc64cf2 commit 1bd07ac

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

lib/net.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -1495,13 +1495,6 @@ Server.prototype.getConnections = function(cb) {
14951495

14961496

14971497
Server.prototype.close = function(cb) {
1498-
function onSlaveClose() {
1499-
if (--left !== 0) return;
1500-
1501-
self._connections = 0;
1502-
self._emitCloseIfDrained();
1503-
}
1504-
15051498
if (typeof cb === 'function') {
15061499
if (!this._handle) {
15071500
this.once('close', function() {
@@ -1518,8 +1511,13 @@ Server.prototype.close = function(cb) {
15181511
}
15191512

15201513
if (this._usingSlaves) {
1521-
var self = this;
15221514
var left = this._slaves.length;
1515+
const onSlaveClose = () => {
1516+
if (--left !== 0) return;
1517+
1518+
this._connections = 0;
1519+
this._emitCloseIfDrained();
1520+
};
15231521

15241522
// Increment connections to be sure that, even if all sockets will be closed
15251523
// during polling of slaves, `close` event will be emitted only once.

0 commit comments

Comments
 (0)