Make sure 'end' is emitted even if no connection has ever happened

This commit is contained in:
Marek 2014-05-13 12:57:01 +01:00
parent 3898f5d8b2
commit 47b0aafa6d
2 changed files with 29 additions and 10 deletions

View File

@ -21,18 +21,22 @@ PG.prototype.end = function() {
var self = this;
var keys = Object.keys(self.pools.all);
var count = keys.length;
keys.forEach(function(key) {
var pool = self.pools.all[key];
delete self.pools.all[key];
pool.drain(function() {
pool.destroyAllNow(function() {
count--;
if(count === 0) {
self.emit('end');
}
if(count === 0) {
self.emit('end');
} else {
keys.forEach(function(key) {
var pool = self.pools.all[key];
delete self.pools.all[key];
pool.drain(function() {
pool.destroyAllNow(function() {
count--;
if(count === 0) {
self.emit('end');
}
});
});
});
});
}
};

View File

@ -0,0 +1,15 @@
var helper = require(__dirname + '/test-helper')
var called = false;
test('disconnects', function() {
called = true;
var eventSink = new helper.Sink(1, function() {});
helper.pg.on('end', function() {
eventSink.add();
});
//this should exit the process
helper.pg.end();
})