Make sure 'end' is emitted even if no connection has ever happened
This commit is contained in:
parent
3898f5d8b2
commit
47b0aafa6d
24
lib/index.js
24
lib/index.js
@ -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');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
15
test/integration/connection-pool/ending-empty-pool-tests.js
Normal file
15
test/integration/connection-pool/ending-empty-pool-tests.js
Normal 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();
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user