@@ -114,31 +114,29 @@ function RoundRobinHandle(key, address, port, addressType, backlog, fd) {
114
114
else
115
115
this . server . listen ( address ) ; // UNIX socket path.
116
116
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 ;
123
122
} ) ;
124
123
}
125
124
126
125
RoundRobinHandle . prototype . add = function ( worker , send ) {
127
126
assert ( worker . id in this . all === false ) ;
128
127
this . all [ worker . id ] = worker ;
129
128
130
- var self = this ;
131
- function done ( ) {
132
- if ( self . handle . getsockname ) {
129
+ const done = ( ) => {
130
+ if ( this . handle . getsockname ) {
133
131
var out = { } ;
134
- self . handle . getsockname ( out ) ;
132
+ this . handle . getsockname ( out ) ;
135
133
// TODO(bnoordhuis) Check err.
136
134
send ( null , { sockname : out } , null ) ;
137
135
} else {
138
136
send ( null , null , null ) ; // UNIX socket.
139
137
}
140
- self . handoff ( worker ) ; // In case there are connections pending.
141
- }
138
+ this . handoff ( worker ) ; // In case there are connections pending.
139
+ } ;
142
140
143
141
if ( this . server === null ) return done ( ) ;
144
142
// Still busy binding.
@@ -180,13 +178,13 @@ RoundRobinHandle.prototype.handoff = function(worker) {
180
178
return ;
181
179
}
182
180
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 ) => {
185
183
if ( reply . accepted )
186
184
handle . close ( ) ;
187
185
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 ) ;
190
188
} ) ;
191
189
} ;
192
190
@@ -399,7 +397,7 @@ function masterInit() {
399
397
cluster . disconnect = function ( cb ) {
400
398
var workers = Object . keys ( cluster . workers ) ;
401
399
if ( workers . length === 0 ) {
402
- process . nextTick ( intercom . emit . bind ( intercom , 'disconnect' ) ) ;
400
+ process . nextTick ( ( ) => intercom . emit ( 'disconnect' ) ) ;
403
401
} else {
404
402
for ( var key in workers ) {
405
403
key = workers [ key ] ;
@@ -421,7 +419,7 @@ function masterInit() {
421
419
signo = signo || 'SIGTERM' ;
422
420
var proc = this . process ;
423
421
if ( this . isConnected ( ) ) {
424
- this . once ( 'disconnect' , proc . kill . bind ( proc , signo ) ) ;
422
+ this . once ( 'disconnect' , ( ) => proc . kill ( signo ) ) ;
425
423
this . disconnect ( ) ;
426
424
return ;
427
425
}
0 commit comments