Skip to content

Commit f574bd4

Browse files
cjihrigevanlucas
authored andcommitted
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 <mic.besace@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>
1 parent abf86ad commit f574bd4

1 file changed

Lines changed: 16 additions & 18 deletions

File tree

‎lib/cluster.js‎

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

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

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

143-
varself=this;
144-
functiondone(){
145-
if(self.handle.getsockname){
142+
constdone=()=>{
143+
if(this.handle.getsockname){
146144
varout={};
147-
self.handle.getsockname(out);
145+
this.handle.getsockname(out);
148146
// TODO(bnoordhuis) Check err.
149147
send(null,{sockname: out},null);
150148
}else{
151149
send(null,null,null);// UNIX socket.
152150
}
153-
self.handoff(worker);// In case there are connections pending.
154-
}
151+
this.handoff(worker);// In case there are connections pending.
152+
};
155153

156154
if(this.server===null)returndone();
157155
// Still busy binding.
@@ -193,13 +191,13 @@ RoundRobinHandle.prototype.handoff = function(worker) {
193191
return;
194192
}
195193
varmessage={act: 'newconn',key: this.key};
196-
varself=this;
197-
sendHelper(worker.process,message,handle,function(reply){
194+
195+
sendHelper(worker.process,message,handle,(reply)=>{
198196
if(reply.accepted)
199197
handle.close();
200198
else
201-
self.distribute(0,handle);// Worker is shutting down. Send to another.
202-
self.handoff(worker);
199+
this.distribute(0,handle);// Worker is shutting down. Send to another.
200+
this.handoff(worker);
203201
});
204202
};
205203

@@ -414,7 +412,7 @@ function masterInit() {
414412
cluster.disconnect=function(cb){
415413
varworkers=Object.keys(cluster.workers);
416414
if(workers.length===0){
417-
process.nextTick(intercom.emit.bind(intercom,'disconnect'));
415+
process.nextTick(()=>intercom.emit('disconnect'));
418416
}else{
419417
for(varkeyinworkers){
420418
key=workers[key];
@@ -436,7 +434,7 @@ function masterInit() {
436434
signo=signo||'SIGTERM';
437435
varproc=this.process;
438436
if(this.isConnected()){
439-
this.once('disconnect',proc.kill.bind(proc,signo));
437+
this.once('disconnect',()=>proc.kill(signo));
440438
this.disconnect();
441439
return;
442440
}

0 commit comments

Comments
 (0)