2
2
const assert = require ( 'assert' ) ;
3
3
const net = require ( 'net' ) ;
4
4
const { sendHelper } = require ( 'internal/cluster/utils' ) ;
5
- const getOwnPropertyNames = Object . getOwnPropertyNames ;
6
5
const uv = process . binding ( 'uv' ) ;
7
6
8
7
module . exports = RoundRobinHandle ;
9
8
10
9
function RoundRobinHandle ( key , address , port , addressType , fd ) {
11
10
this . key = key ;
12
- this . all = { } ;
11
+ this . all = new Map ( ) ;
13
12
this . free = [ ] ;
14
13
this . handles = [ ] ;
15
14
this . handle = null ;
@@ -31,8 +30,8 @@ function RoundRobinHandle(key, address, port, addressType, fd) {
31
30
}
32
31
33
32
RoundRobinHandle . 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 ) ;
36
35
37
36
const done = ( ) => {
38
37
if ( this . handle . getsockname ) {
@@ -61,16 +60,17 @@ RoundRobinHandle.prototype.add = function(worker, send) {
61
60
} ;
62
61
63
62
RoundRobinHandle . prototype . remove = function ( worker ) {
64
- if ( worker . id in this . all === false )
63
+ const existed = this . all . delete ( worker . id ) ;
64
+
65
+ if ( ! existed )
65
66
return false ;
66
67
67
- delete this . all [ worker . id ] ;
68
68
const index = this . free . indexOf ( worker ) ;
69
69
70
70
if ( index !== - 1 )
71
71
this . free . splice ( index , 1 ) ;
72
72
73
- if ( getOwnPropertyNames ( this . all ) . length !== 0 )
73
+ if ( this . all . size !== 0 )
74
74
return false ;
75
75
76
76
for ( var handle ; handle = this . handles . shift ( ) ; handle . close ( ) )
@@ -90,7 +90,7 @@ RoundRobinHandle.prototype.distribute = function(err, handle) {
90
90
} ;
91
91
92
92
RoundRobinHandle . prototype . handoff = function ( worker ) {
93
- if ( worker . id in this . all === false ) {
93
+ if ( this . all . has ( worker . id ) === false ) {
94
94
return ; // Worker is closing (or has closed) the server.
95
95
}
96
96
0 commit comments