Skip to content

Commit

Permalink
net: refactor onSlaveClose in Server.close
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
claudiorodriguez authored and andrew749 committed Jul 19, 2017
1 parent 6928cd7 commit 9202ab0
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -1495,13 +1495,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() {
Expand All @@ -1518,8 +1511,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.
Expand Down

0 comments on commit 9202ab0

Please sign in to comment.