I was reading http://howtonode.org/understanding-process-next-tick However, the code it come with does not implement CPU-intensive task.
I tried to write my version. But it is wrong.
None of the IO is serving after compute() get executed.
So, my question is: What's the proper way to use nextTick() function under this scenario ?
I don't want to block IO when compute() is executing.
var http = require('http');
function compute() {
// performs complicated calculations continuously
// ...
var result = 0;
for(var i = 0; i < 1000000; i++){
for(var j = i; j < 1000000; j++){
result += i + j;
}
}
process.nextTick(compute);
}
http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World');
}).listen(5000, '127.0.0.1');
compute();