Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Child Process nodejs
var context = [];
(function(context){
setInterval(function(){
var value = context.pop()
console.log('iteraciones ' + value);
},1000);
})(context);
process.on('message',function(value){
console.log('mensaje recibido');
context.push(value);
});
var http = require('http');
var process = require('child_process');
var app = http.createServer(function(req,res){
child.send({'key':'value'})
res.end('hello');
});
console.log('server running');
// se realiza el fork del nuevo proceso
var child = process.fork('task.js');
// dispara el evento message hacia el fork
child.send({'key':'valor'})
console.log('proceso hijo iniciado');
app.listen(3000);
var context = [];
var process = function(){
var value = context.pop()
console.log('iteraciones ' + value);
}
process.on('message',function(value){
console.log('mensaje recibido');
context.push(value);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment