net: defer net.Server 'close' event to next tick

v0.7.4-release
Ben Noordhuis 2011-12-29 19:30:07 +01:00
parent 0c3b357985
commit c24276f008
2 changed files with 10 additions and 3 deletions

View File

@ -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');
});
};

View File

@ -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();
});