Skip to content

Commit 9202ab0

Browse files
claudiorodriguezandrew749
authored andcommittedJul 19, 2017
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: nodejs/node#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 6928cd7 commit 9202ab0

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)
Please sign in to comment.