22const assert = require ( 'assert' ) ;
33const net = require ( 'net' ) ;
44const { sendHelper } = require ( 'internal/cluster/utils' ) ;
5- const getOwnPropertyNames = Object . getOwnPropertyNames ;
65const uv = process . binding ( 'uv' ) ;
76
87module . exports = RoundRobinHandle ;
98
109function RoundRobinHandle ( key , address , port , addressType , fd ) {
1110 this . key = key ;
12- this . all = { } ;
11+ this . all = new Map ( ) ;
1312 this . free = [ ] ;
1413 this . handles = [ ] ;
1514 this . handle = null ;
@@ -31,8 +30,8 @@ function RoundRobinHandle(key, address, port, addressType, fd) {
3130}
3231
3332RoundRobinHandle . prototype . add = function ( worker , send ) {
34- assert ( worker . id in this . all === false ) ;
35- this . all [ worker . id ] = worker ;
33+ assert ( this . all . has ( worker . id ) === false ) ;
34+ this . all . set ( worker . id , worker ) ;
3635
3736 const done = ( ) => {
3837 if ( this . handle . getsockname ) {
@@ -61,16 +60,17 @@ RoundRobinHandle.prototype.add = function(worker, send) {
6160} ;
6261
6362RoundRobinHandle . prototype . remove = function ( worker ) {
64- if ( worker . id in this . all === false )
63+ const existed = this . all . delete ( worker . id ) ;
64+
65+ if ( ! existed )
6566 return false ;
6667
67- delete this . all [ worker . id ] ;
6868 const index = this . free . indexOf ( worker ) ;
6969
7070 if ( index !== - 1 )
7171 this . free . splice ( index , 1 ) ;
7272
73- if ( getOwnPropertyNames ( this . all ) . length !== 0 )
73+ if ( this . all . size !== 0 )
7474 return false ;
7575
7676 for ( var handle ; handle = this . handles . shift ( ) ; handle . close ( ) )
@@ -90,7 +90,7 @@ RoundRobinHandle.prototype.distribute = function(err, handle) {
9090} ;
9191
9292RoundRobinHandle . prototype . handoff = function ( worker ) {
93- if ( worker . id in this . all === false ) {
93+ if ( this . all . has ( worker . id ) === false ) {
9494 return ; // Worker is closing (or has closed) the server.
9595 }
9696
0 commit comments