mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
1 parent
440f4d4eef
commit
8ac387be3e
1 file changed
+6
-8
+6
-8
@@ -1517,13 +1517,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 close() {
|
||||
@@ -1540,8 +1533,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.
|
||||
|
||||
Reference in new issue
Block a user