Last active
August 29, 2015 14:10
-
-
Save JacobHsu/fc97ee158d0ff9d6cdd2 to your computer and use it in GitHub Desktop.
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
pollingLoop(); | |
function pollingLoop(){ | |
var cp = require('child_process'); | |
var child = cp.fork('./worker'); | |
var num = Math.floor((Math.random() * 100) + 1); | |
child.on('message', function(m) { | |
// Receive results from child process | |
console.log('Child process started: %d', child.pid); | |
console.log('received: ' + m); | |
}); | |
// Send child process some work | |
child.send({ word: 'Please up-case this string', random: num}); | |
setTimeout(pollingLoop, 3000); | |
} |
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
process.on('message', function(m) { | |
// Do work (in this case just up-case the string | |
word = m.word.toUpperCase(); | |
num = m.random; | |
// Pass results back to parent process | |
process.send(word+' '+num); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment