Child Process nodejs
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
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); | |
}); |
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
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); |
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
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