File tree Expand file tree Collapse file tree 1 file changed +20
-4
lines changed
Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -139,14 +139,30 @@ Worker.prototype.connect = function(id, options){
139139} ;
140140
141141/**
142- * Immediate shutdown.
142+ * Shutdown the process (using process.nextTick to put it at the end of
143+ * event queue).
144+ *
145+ * If the master is listening on the 'worker close' event, a callback
146+ * is passed. The callback *must* be called to shutdown the worker.
143147 *
144148 * @api private
145149 */
146150
147- Worker . prototype . destroy = function ( ) {
148- this . emit ( 'close' ) ;
149- process . nextTick ( process . exit ) ;
151+ Worker . prototype . destroy = function ( ) {
152+ var eventName = 'worker close'
153+ , listeners = this . master . listeners ( eventName ) ;
154+
155+ var exit = function ( ) {
156+ process . nextTick ( process . exit ( ) ) ;
157+ } ;
158+
159+ if ( listeners . length > 0 ) {
160+ this . master . emit ( eventName , function ( ) {
161+ exit ( ) ;
162+ } ) ;
163+ } else {
164+ exit ( ) ;
165+ }
150166} ;
151167
152168/**
You can’t perform that action at this time.
0 commit comments