Last active
December 21, 2015 10:39
-
-
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…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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