Skip to content

Instantly share code, notes, and snippets.

@nathanaschbacher
Created May 7, 2012 19:23
Show Gist options
  • Save nathanaschbacher/2629823 to your computer and use it in GitHub Desktop.
Save nathanaschbacher/2629823 to your computer and use it in GitHub Desktop.
Trying to work with Node.js child_process
module.exports = function(input, args) {
var expensiveResults = // Do some computationally expensive stuff with input and args...
this.emit('results', expensiveResults);
}
// 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