Skip to content

Instantly share code, notes, and snippets.

@BlaShadow
Created March 28, 2014 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BlaShadow/9836171 to your computer and use it in GitHub Desktop.
Save BlaShadow/9836171 to your computer and use it in GitHub Desktop.
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