Use res.end() to finish the connection.  If you are just sending the return
data once, use res.end(data).


On Wed, Feb 20, 2013 at 10:08 PM, <benppt...@tacol.biz> wrote:

> 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 nodejs@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+unsubscr...@googlegroups.com
> 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 nodejs+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
-- 
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 nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
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 nodejs+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to