Created
May 7, 2012 19:23
-
-
Save nathanaschbacher/2629823 to your computer and use it in GitHub Desktop.
Trying to work with Node.js child_process
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
module.exports = function(input, args) { | |
var expensiveResults = // Do some computationally expensive stuff with input and args... | |
this.emit('results', expensiveResults); | |
} |
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
// What I want is to be able to send data to a child process that contains a function that crunches the data and returns the results to the parent... I just don't quite get how to do that. | |
var child_process = require('child_process'); | |
function run_in_child_process(input, args, options, _return) { | |
new_child = child_process.fork('/expensive_process.js', args, options); // Somehow I need to get 'input' in there...? | |
new_child.on('results', _return); // return is the passed in callback, setup like function(err,data) {} | |
new_child.on('exit', function(code, signal) { | |
console.dir(code); | |
console.dir(signal); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment