Make sure 'end' is emitted even if no connection has ever happened

This commit is contained in:
Marek 2014-05-13 12:57:01 +01:00
parent 3898f5d8b2
commit 47b0aafa6d
2 changed files with 29 additions and 10 deletions

View File

@ -21,6 +21,9 @@ 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;
if(count === 0) {
self.emit('end');
} else {
keys.forEach(function(key) { keys.forEach(function(key) {
var pool = self.pools.all[key]; var pool = self.pools.all[key];
delete self.pools.all[key]; delete self.pools.all[key];
@ -33,6 +36,7 @@ PG.prototype.end = function() {
}); });
}); });
}); });
}
}; };

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