Great Node.js!! I do love it.
Not sure if I can post question here. Apologized if I am wrong.
I am wondering how can I finish the request and do something time
consuming, e.g. email/file conversion...etc.
I've tried the following four ways, but all of them take long time to
return the response in browser.
Is there any way I can do something after the request is finished? Just
like PHP FPM *fastcgi_finish_request()* in Express Project?
#1 Use res.render callback
function(req, res){
res.render('someview', function(err, html){
if (err){ console.log('debug-err:', err);
res.send(html);
var result = 1;
for (var i = 0, j = 10; i < 10000000000; i++){
result = result + i + j;
}
console.log('debug',result);
});
}
#2 Use setTimeout:
function(req, res){
res.render('someview');
setTimeout(function(){
var result = 1;
for (var i = 0, j = 10; i < 10000000000; i++){
result = result + i + j;
}
console.log('debug',result);
}, 0);
}
#3 Use process.nextTick:
function(req, res){
res.render('someview');
process.nextTick(function(){
var result = 1;
for (var i = 0, j = 10; i < 10000000000; i++){
result = result + i + j;
}
console.log('debug',result);
});
}
#4 Simply do it, because res.render won't block the I/O
function(req, res){
res.render('someview');
var result = 1;
for (var i = 0, j = 10; i < 10000000000; i++){
result = result + i + j;
}
console.log('debug',result);
}
Appreciated for any explanation for understanding Node.js event I/O. Thank
you very much :)
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.