Skip to content

Commit 615167b

Browse files
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 6c60691 commit 615167b

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

15401540

15411541
Server.prototype.close = function(cb) {
1542-
function onSlaveClose() {
1543-
if (--left !== 0) return;
1544-
1545-
self._connections = 0;
1546-
self._emitCloseIfDrained();
1547-
}
1548-
15491542
if (typeof cb === 'function') {
15501543
if (!this._handle) {
15511544
this.once('close', function close() {
@@ -1562,8 +1555,13 @@ Server.prototype.close = function(cb) {
15621555
}
15631556

15641557
if (this._usingSlaves) {
1565-
var self = this;
15661558
var left = this._slaves.length;
1559+
const onSlaveClose = () => {
1560+
if (--left !== 0) return;
1561+
1562+
this._connections = 0;
1563+
this._emitCloseIfDrained();
1564+
};
15671565

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

0 commit comments

Comments
 (0)