Skip to content

Commit 227db0a

Browse files
cjihrigMylesBorins
authored andcommittedOct 26, 2016
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 b0e2f9a commit 227db0a

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed
 

‎lib/cluster.js

+16-18
Original file line numberDiff line numberDiff line change
@@ -114,31 +114,29 @@ function RoundRobinHandle(key, address, port, addressType, backlog, fd) {
114114
else
115115
this.server.listen(address); // UNIX socket path.
116116

117-
var self = this;
118-
this.server.once('listening', function() {
119-
self.handle = self.server._handle;
120-
self.handle.onconnection = self.distribute.bind(self);
121-
self.server._handle = null;
122-
self.server = null;
117+
this.server.once('listening', () => {
118+
this.handle = this.server._handle;
119+
this.handle.onconnection = (err, handle) => this.distribute(err, handle);
120+
this.server._handle = null;
121+
this.server = null;
123122
});
124123
}
125124

126125
RoundRobinHandle.prototype.add = function(worker, send) {
127126
assert(worker.id in this.all === false);
128127
this.all[worker.id] = worker;
129128

130-
var self = this;
131-
function done() {
132-
if (self.handle.getsockname) {
129+
const done = () => {
130+
if (this.handle.getsockname) {
133131
var out = {};
134-
self.handle.getsockname(out);
132+
this.handle.getsockname(out);
135133
// TODO(bnoordhuis) Check err.
136134
send(null, { sockname: out }, null);
137135
} else {
138136
send(null, null, null); // UNIX socket.
139137
}
140-
self.handoff(worker); // In case there are connections pending.
141-
}
138+
this.handoff(worker); // In case there are connections pending.
139+
};
142140

143141
if (this.server === null) return done();
144142
// Still busy binding.
@@ -180,13 +178,13 @@ RoundRobinHandle.prototype.handoff = function(worker) {
180178
return;
181179
}
182180
var message = { act: 'newconn', key: this.key };
183-
var self = this;
184-
sendHelper(worker.process, message, handle, function(reply) {
181+
182+
sendHelper(worker.process, message, handle, (reply) => {
185183
if (reply.accepted)
186184
handle.close();
187185
else
188-
self.distribute(0, handle); // Worker is shutting down. Send to another.
189-
self.handoff(worker);
186+
this.distribute(0, handle); // Worker is shutting down. Send to another.
187+
this.handoff(worker);
190188
});
191189
};
192190

@@ -399,7 +397,7 @@ function masterInit() {
399397
cluster.disconnect = function(cb) {
400398
var workers = Object.keys(cluster.workers);
401399
if (workers.length === 0) {
402-
process.nextTick(intercom.emit.bind(intercom, 'disconnect'));
400+
process.nextTick(() => intercom.emit('disconnect'));
403401
} else {
404402
for (var key in workers) {
405403
key = workers[key];
@@ -421,7 +419,7 @@ function masterInit() {
421419
signo = signo || 'SIGTERM';
422420
var proc = this.process;
423421
if (this.isConnected()) {
424-
this.once('disconnect', proc.kill.bind(proc, signo));
422+
this.once('disconnect', () => proc.kill(signo));
425423
this.disconnect();
426424
return;
427425
}

0 commit comments

Comments
 (0)
Please sign in to comment.