Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,23 @@ util.inherits(PG, EventEmitter);

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


PG.prototype.connect = function(config, callback) {
if(typeof config == "function") {
callback = config;
Expand Down
5 changes: 5 additions & 0 deletions test/integration/connection-pool/ending-pool-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ var called = false;
test('disconnects', function() {
var sink = new helper.Sink(4, function() {
called = true;
var eventSink = new helper.Sink(1, function() {});
helper.pg.on('end', function() {
eventSink.add();
});

//this should exit the process, killing each connection pool
helper.pg.end();
});
Expand Down