@@ -27,7 +27,20 @@ function Worker(options) {
2727 if ( options === null || typeof options !== 'object' )
2828 options = { } ;
2929
30- this . suicide = undefined ;
30+ this . exitedAfterDisconnect = undefined ;
31+
32+ Object . defineProperty ( this , 'suicide' , {
33+ get : function ( ) {
34+ // TODO: Print deprecation message.
35+ return this . exitedAfterDisconnect ;
36+ } ,
37+ set : function ( val ) {
38+ // TODO: Print deprecation message.
39+ this . exitedAfterDisconnect = val ;
40+ } ,
41+ enumerable : true
42+ } ) ;
43+
3144 this . state = options . state || 'none' ;
3245 this . id = options . id | 0 ;
3346
@@ -355,7 +368,7 @@ function masterInit() {
355368 removeWorker ( worker ) ;
356369 }
357370
358- worker . suicide = ! ! worker . suicide ;
371+ worker . exitedAfterDisconnect = ! ! worker . exitedAfterDisconnect ;
359372 worker . state = 'dead' ;
360373 worker . emit ( 'exit' , exitCode , signalCode ) ;
361374 cluster . emit ( 'exit' , worker , exitCode , signalCode ) ;
@@ -376,7 +389,7 @@ function masterInit() {
376389 */
377390 if ( worker . isDead ( ) ) removeWorker ( worker ) ;
378391
379- worker . suicide = ! ! worker . suicide ;
392+ worker . exitedAfterDisconnect = ! ! worker . exitedAfterDisconnect ;
380393 worker . state = 'disconnected' ;
381394 worker . emit ( 'disconnect' ) ;
382395 cluster . emit ( 'disconnect' , worker ) ;
@@ -407,7 +420,7 @@ function masterInit() {
407420 } ;
408421
409422 Worker . prototype . disconnect = function ( ) {
410- this . suicide = true ;
423+ this . exitedAfterDisconnect = true ;
411424 send ( this , { act : 'disconnect' } ) ;
412425 removeHandlesForWorker ( this ) ;
413426 removeWorker ( this ) ;
@@ -432,8 +445,8 @@ function masterInit() {
432445 queryServer ( worker , message ) ;
433446 else if ( message . act === 'listening' )
434447 listening ( worker , message ) ;
435- else if ( message . act === 'suicide ' )
436- suicide ( worker , message ) ;
448+ else if ( message . act === 'exitedAfterDisconnect ' )
449+ exitedAfterDisconnect ( worker , message ) ;
437450 else if ( message . act === 'close' )
438451 close ( worker , message ) ;
439452 }
@@ -444,14 +457,14 @@ function masterInit() {
444457 cluster . emit ( 'online' , worker ) ;
445458 }
446459
447- function suicide ( worker , message ) {
448- worker . suicide = true ;
460+ function exitedAfterDisconnect ( worker , message ) {
461+ worker . exitedAfterDisconnect = true ;
449462 send ( worker , { ack : message . seq } ) ;
450463 }
451464
452465 function queryServer ( worker , message ) {
453466 // Stop processing if worker already disconnecting
454- if ( worker . suicide )
467+ if ( worker . exitedAfterDisconnect )
455468 return ;
456469 var args = [ message . address ,
457470 message . port ,
@@ -533,7 +546,7 @@ function workerInit() {
533546 cluster . worker = worker ;
534547 process . once ( 'disconnect' , function ( ) {
535548 worker . emit ( 'disconnect' ) ;
536- if ( ! worker . suicide ) {
549+ if ( ! worker . exitedAfterDisconnect ) {
537550 // Unexpected disconnect, master exited, or some such nastiness, so
538551 // worker exits immediately.
539552 process . exit ( 0 ) ;
@@ -670,10 +683,10 @@ function workerInit() {
670683 } ;
671684
672685 Worker . prototype . destroy = function ( ) {
673- this . suicide = true ;
686+ this . exitedAfterDisconnect = true ;
674687 if ( ! this . isConnected ( ) ) process . exit ( 0 ) ;
675688 var exit = process . exit . bind ( null , 0 ) ;
676- send ( { act : 'suicide ' } , ( ) => process . disconnect ( ) ) ;
689+ send ( { act : 'exitedAfterDisconnect ' } , ( ) => process . disconnect ( ) ) ;
677690 process . once ( 'disconnect' , exit ) ;
678691 } ;
679692
@@ -682,19 +695,20 @@ function workerInit() {
682695 }
683696
684697 function _disconnect ( masterInitiated ) {
685- this . suicide = true ;
698+ this . exitedAfterDisconnect = true ;
686699 let waitingCount = 1 ;
687700
688701 function checkWaitingCount ( ) {
689702 waitingCount -- ;
690703 if ( waitingCount === 0 ) {
691- // If disconnect is worker initiated, wait for ack to be sure suicide
692- // is properly set in the master, otherwise, if it's master initiated
693- // there's no need to send the suicide message
704+ // If disconnect is worker initiated, wait for ack to be sure
705+ // exitedAfterDisconnect is properly set in the master, otherwise, if
706+ // it's master initiated there's no need to send the
707+ // exitedAfterDisconnect message
694708 if ( masterInitiated ) {
695709 process . disconnect ( ) ;
696710 } else {
697- send ( { act : 'suicide ' } , ( ) => process . disconnect ( ) ) ;
711+ send ( { act : 'exitedAfterDisconnect ' } , ( ) => process . disconnect ( ) ) ;
698712 }
699713 }
700714 }
0 commit comments