adam
adam

Reputation: 1453

'net' refuses to emit 'close' event in nodejs

hi I have the following code:

this.stop = function() {
    this.server.close();
    var thisServer = this;
    this.server.on('close',function() {
        thisServer.emit('stop');        
    });     
};

after using the server and calling the stop function, the server refuses to emit 'close' event and

    this.server.on('close',function() {
        thisServer.emit('stop');        
    }); 

am I doing something wrong?

Upvotes: 0

Views: 316

Answers (1)

Raynos
Raynos

Reputation: 169391

this.server.on('close',function() {
    thisServer.emit('stop');        
});    
this.server.close();
var thisServer = this;

Bind the close event before you invoke close.

Alternatively try this.server.destroy();

Upvotes: 1

Related Questions