Merge pull request #571 from letsface/ended-event-on-pool-drained

emit event 'ended' on pool drained
This commit is contained in:
Brian C 2014-04-22 16:27:57 -05:00
commit 1047aeb3c2
2 changed files with 15 additions and 2 deletions

View File

@ -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;

View File

@ -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();
});