Skip to content

Instantly share code, notes, and snippets.

@stagas stagas/fork.js
Created May 12, 2012

Embed
What would you like to do?
var n = +(process.argv[2] || 10000)
var cp = require('child_process')
var child = cp.fork(__dirname + '/worker.js')
console.log('trying', n, 'messages')
var total = n
child.on('message', function () {
if (!--total) console.log('completed %d roundtrips', n - total)
else if (!(total % 1000)) console.log('%d roundtrips', n - total)
})
for (var i = n; i--;) {
child.send('a')
}
var r = 0
process.on('message', function () {
process.send('b')
if (!(r % 1000)) console.log('received: %d', ++r)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.