Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,30 @@ Worker.prototype.connect = function(id, options){
};

/**
* Immediate shutdown.
* Shutdown the process (using process.nextTick to put it at the end of
* event queue).
*
* If the master is listening on the 'worker close' event, a callback
* is passed. The callback *must* be called to shutdown the worker.
*
* @api private
*/

Worker.prototype.destroy = function(){
this.emit('close');
process.nextTick(process.exit);
Worker.prototype.destroy = function() {
var eventName = 'worker close'
, listeners = this.master.listeners(eventName);

var exit = function() {
process.nextTick(process.exit());
};

if (listeners.length > 0) {
this.master.emit(eventName, function() {
exit();
});
} else {
exit();
}
};

/**
Expand Down