Skip to content

Instantly share code, notes, and snippets.

@EdJ
Last active December 21, 2015 10:39
Show Gist options
  • Save EdJ/6293376 to your computer and use it in GitHub Desktop.
Save EdJ/6293376 to your computer and use it in GitHub Desktop.
Basic event emitting demonstration, showing the in-worker emits, but not the ability to emit beyond the worker boundary. This prevents me manually triggering the 'listening' event that a net.Server emits when it opens, and therefore stops me doing hot-patching when releasing in the same manner between a front-end webserver and a backend RabbitMQ…
var cluster = require('cluster');
if (cluster.isMaster) {
var worker = cluster.fork();
worker.on('test', function() {
console.log('worker is listening');
});
} else {
process.on('test', function() {
console.log('test');
});
setInterval(function() {
console.log('still running');
}, 500);
setTimeout(function() {
process.emit('test', 'some data');
}, 2000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment