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:
parent
a95d9ac711
commit
a536afb1a8
@ -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) {
|
||||
|
@ -122,6 +122,9 @@ Connection.prototype.attachListeners = function(stream) {
|
||||
packet = self._reader.read();
|
||||
}
|
||||
});
|
||||
stream.on('end', function() {
|
||||
self.emit('end');
|
||||
});
|
||||
};
|
||||
|
||||
Connection.prototype.requestSsl = function() {
|
||||
|
6
test/integration/client/end-callback-tests.js
Normal file
6
test/integration/client/end-callback-tests.js
Normal file
@ -0,0 +1,6 @@
|
||||
var helper = require('./test-helper')
|
||||
|
||||
var client = helper.client(assert.success(function() {
|
||||
client.end(assert.success(function() {
|
||||
}))
|
||||
}))
|
@ -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;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user