Skip to content

Commit 45367a2

Browse files
committed
cluster: remove bind() and self
This commit removes the use of self and bind() from the cluster module in favor of arrow functions. PR-URL: #7710 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
1 parent 9dc0651 commit 45367a2

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

lib/cluster.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -128,31 +128,29 @@ function RoundRobinHandle(key, address, port, addressType, backlog, fd) {
128128
else
129129
this.server.listen(address); // UNIX socket path.
130130

131-
var self = this;
132-
this.server.once('listening', function() {
133-
self.handle = self.server._handle;
134-
self.handle.onconnection = self.distribute.bind(self);
135-
self.server._handle = null;
136-
self.server = null;
131+
this.server.once('listening', () => {
132+
this.handle = this.server._handle;
133+
this.handle.onconnection = (err, handle) => this.distribute(err, handle);
134+
this.server._handle = null;
135+
this.server = null;
137136
});
138137
}
139138

140139
RoundRobinHandle.prototype.add = function(worker, send) {
141140
assert(worker.id in this.all === false);
142141
this.all[worker.id] = worker;
143142

144-
var self = this;
145-
function done() {
146-
if (self.handle.getsockname) {
143+
const done = () => {
144+
if (this.handle.getsockname) {
147145
var out = {};
148-
self.handle.getsockname(out);
146+
this.handle.getsockname(out);
149147
// TODO(bnoordhuis) Check err.
150148
send(null, { sockname: out }, null);
151149
} else {
152150
send(null, null, null); // UNIX socket.
153151
}
154-
self.handoff(worker); // In case there are connections pending.
155-
}
152+
this.handoff(worker); // In case there are connections pending.
153+
};
156154

157155
if (this.server === null) return done();
158156
// Still busy binding.
@@ -194,13 +192,13 @@ RoundRobinHandle.prototype.handoff = function(worker) {
194192
return;
195193
}
196194
var message = { act: 'newconn', key: this.key };
197-
var self = this;
198-
sendHelper(worker.process, message, handle, function(reply) {
195+
196+
sendHelper(worker.process, message, handle, (reply) => {
199197
if (reply.accepted)
200198
handle.close();
201199
else
202-
self.distribute(0, handle); // Worker is shutting down. Send to another.
203-
self.handoff(worker);
200+
this.distribute(0, handle); // Worker is shutting down. Send to another.
201+
this.handoff(worker);
204202
});
205203
};
206204

@@ -415,7 +413,7 @@ function masterInit() {
415413
cluster.disconnect = function(cb) {
416414
var workers = Object.keys(cluster.workers);
417415
if (workers.length === 0) {
418-
process.nextTick(intercom.emit.bind(intercom, 'disconnect'));
416+
process.nextTick(() => intercom.emit('disconnect'));
419417
} else {
420418
for (var key in workers) {
421419
key = workers[key];
@@ -437,7 +435,7 @@ function masterInit() {
437435
signo = signo || 'SIGTERM';
438436
var proc = this.process;
439437
if (this.isConnected()) {
440-
this.once('disconnect', proc.kill.bind(proc, signo));
438+
this.once('disconnect', () => proc.kill(signo));
441439
this.disconnect();
442440
return;
443441
}

0 commit comments

Comments
 (0)