mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
emit event when all pool are actually destroyed
This commit is contained in:
parent
fb9876c896
commit
382d6d66f9
@ -19,15 +19,22 @@ 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();
|
||||
count--;
|
||||
if(count === 0) {
|
||||
self.emit('ended');
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
PG.prototype.connect = function(config, callback) {
|
||||
if(typeof config == "function") {
|
||||
callback = config;
|
||||
|
||||
@ -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('ended', function() {
|
||||
eventSink.add();
|
||||
});
|
||||
|
||||
//this should exit the process, killing each connection pool
|
||||
helper.pg.end();
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user