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 self = this;
|
||||||
var keys = Object.keys(self.pools.all);
|
var keys = Object.keys(self.pools.all);
|
||||||
var count = keys.length;
|
var count = keys.length;
|
||||||
keys.forEach(function(key) {
|
if(count === 0) {
|
||||||
var pool = self.pools.all[key];
|
self.emit('end');
|
||||||
delete self.pools.all[key];
|
} else {
|
||||||
pool.drain(function() {
|
keys.forEach(function(key) {
|
||||||
pool.destroyAllNow(function() {
|
var pool = self.pools.all[key];
|
||||||
count--;
|
delete self.pools.all[key];
|
||||||
if(count === 0) {
|
pool.drain(function() {
|
||||||
self.emit('end');
|
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