Skip to content

Commit 8ac387b

Browse files
claudiorodriguezevanlucas
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 <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]>
1 parent 440f4d4 commit 8ac387b

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
@@ -1517,13 +1517,6 @@ Server.prototype.getConnections = function(cb) {
15171517

15181518

15191519
Server.prototype.close = function(cb) {
1520-
function onSlaveClose() {
1521-
if (--left !== 0) return;
1522-
1523-
self._connections = 0;
1524-
self._emitCloseIfDrained();
1525-
}
1526-
15271520
if (typeof cb === 'function') {
15281521
if (!this._handle) {
15291522
this.once('close', function close() {
@@ -1540,8 +1533,13 @@ Server.prototype.close = function(cb) {
15401533
}
15411534

15421535
if (this._usingSlaves) {
1543-
var self = this;
15441536
var left = this._slaves.length;
1537+
const onSlaveClose = () => {
1538+
if (--left !== 0) return;
1539+
1540+
this._connections = 0;
1541+
this._emitCloseIfDrained();
1542+
};
15451543

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

0 commit comments

Comments
 (0)