Merge pull request #32 from hetul/fix-closing-finished-connections

Fix closing a finished cursor without supplying a callback
This commit is contained in:
Brian C 2019-12-18 12:38:30 -06:00 committed by GitHub
commit e34c6021ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -175,7 +175,11 @@ Cursor.prototype.end = util.deprecate(function(cb) {
Cursor.prototype.close = function(cb) {
if (this.state === 'done') {
return setImmediate(cb)
if (cb) {
return setImmediate(cb)
} else {
return
}
}
this._closePortal()
this.state = 'done'

View File

@ -10,6 +10,16 @@ describe('close', function() {
client.on('drain', client.end.bind(client))
})
it('can close a finished cursor without a callback', function(done) {
const cursor = new Cursor(text)
this.client.query(cursor)
this.client.query('SELECT NOW()', done)
cursor.read(100, function(err) {
assert.ifError(err)
cursor.close()
})
})
it('closes cursor early', function(done) {
const cursor = new Cursor(text)
this.client.query(cursor)