Add callback to client#end (#1106)

A long standing bug was the pure JS client didn't accept or call a callback on `client.end`.  This is inconsistent with both the documentation & general node patterns.

This fixes the issue & adds a test.  The issue did not exist in the native version of the client.
This commit is contained in:
Brian C 2016-08-11 10:17:03 -05:00 committed by GitHub
parent a95d9ac711
commit a536afb1a8
4 changed files with 15 additions and 3 deletions

View File

@ -336,8 +336,11 @@ Client.prototype.query = function(config, values, callback) {
return query;
};
Client.prototype.end = function() {
Client.prototype.end = function(cb) {
this.connection.end();
if (cb) {
this.connection.once('end', cb);
}
};
Client.md5 = function(string) {

View File

@ -122,6 +122,9 @@ Connection.prototype.attachListeners = function(stream) {
packet = self._reader.read();
}
});
stream.on('end', function() {
self.emit('end');
});
};
Connection.prototype.requestSsl = function() {

View File

@ -0,0 +1,6 @@
var helper = require('./test-helper')
var client = helper.client(assert.success(function() {
client.end(assert.success(function() {
}))
}))

View File

@ -7,9 +7,9 @@ if(helper.args.native) {
}
//creates a client from cli parameters
helper.client = function() {
helper.client = function(cb) {
var client = new Client(helper.config);
client.connect();
client.connect(cb);
return client;
};