Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

cluster: simplify process event handling

This simplify the internalMessage and exit event handling
And simply relay message and error event to the worker object
Note that the error event was not relayed before
  • Loading branch information
AndreasMadsen authored and isaacs committed Feb 1, 2012
1 parent 5e1471c commit a20872045a1e153f6687d37f4d824739e3a60b27
Showing with 7 additions and 21 deletions.
  1. +7 −21 lib/cluster.js
@@ -169,7 +169,7 @@ function handleResponse(outMessage, outHandle, inMessage, inHandle, worker) {

// Handle messages from both master and workers
var messageHandingObject = {};
function handleMessage(inMessage, inHandle, worker) {
function handleMessage(worker, inMessage, inHandle) {

//Remove internal prefix
var message = extendObject({}, inMessage);
@@ -303,27 +303,13 @@ function Worker(customEnv) {
});
}

// Internal message: handle message
this.process.on('internalMessage', function(message, handle) {
debug('recived: ', message);
// handle internalMessage and exit event
this.process.on('internalMessage', handleMessage.bind(null, this));
this.process.on('exit', prepareDeath.bind(null, this, 'dead', 'death'));

// relay to handleMessage
handleMessage(message, handle, self);
return;
});

// Non-internal message: relay to Worker object
this.process.on('message', function(message, handle) {
self.emit('message', message, handle);
});

// Handle exit
self.process.on('exit', function() {
debug('worker id=' + self.uniqueID + ' died');

// Prepare worker to die and emit events
prepareDeath(self, 'dead', 'death');
});
// relay message and error
this.process.on('message', this.emit.bind(this, 'message'));
this.process.on('error', this.emit.bind(this, 'error'));

}
util.inherits(Worker, EventEmitter);

0 comments on commit a208720

Please sign in to comment.
You can’t perform that action at this time.