brianc/node-postgres — pull request #571 by rngadam (2014-04-17 08:28:48+00:00)
Title: emit event 'ended' on pool drained

I've noticed that there's no real way that I could see to be notified that all the pools have actually destroyed all their resources successfully. pg.end() ends just orders the pool to drain and destroyAllNow, but doesn't notify anyone when these actions are completed.

This change lets us do this with a new event "ended":

```
var deferred = Q.defer();
pg.on('ended', function() {
deferred.resolve();
});
pg.on('error', function(err) {
deferred.reject(err);
});
pg.end();
return deferred.promise;
```