Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
net: defer net.Server 'close' event to next tick
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Dec 29, 2011
1 parent 0c3b357 commit c24276f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/net.js
Expand Up @@ -862,9 +862,13 @@ Server.prototype.close = function() {
};

Server.prototype._emitCloseIfDrained = function() {
if (!this._handle && !this.connections) {
this.emit('close');
}
var self = this;

if (self._handle || self.connections) return;

process.nextTick(function() {
self.emit('close');
});
};


Expand Down
3 changes: 3 additions & 0 deletions test/simple/test-net-server-listen-remove-callback.js
Expand Up @@ -34,6 +34,9 @@ server.on('close', function() {

server.listen(common.PORT, function() {
server.close();
});

server.once('close', function() {
server.listen(common.PORT + 1, function() {
server.close();
});
Expand Down

0 comments on commit c24276f

Please sign in to comment.