Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine for sure if Node.js server response is stopped?

How can I determine if server.HttpResponse stopped without listenng to "end" or "close" events?

What I am trying to achieve is something like this:

http.createServer(function (request, response) {
    var foo; // my event emitting object

    // ... something compilated happens here ...

    foo.onSomeEvent(function () {
        if (response.hasEnded) {
            // do something
        }
    });
});
like image 247
Mateusz Charytoniuk Avatar asked Oct 16 '13 09:10

Mateusz Charytoniuk


1 Answers

You can check the finished property on the response object:

if (res.finished) {
  ...
}

(never used it myself, so not sure if there are any potential problems to take into consideration when using it)

like image 65
robertklep Avatar answered Sep 27 '22 19:09

robertklep