Skip to content

Commit

Permalink
Merge pull request #32 from hetul/fix-closing-finished-connections
Browse files Browse the repository at this point in the history
Fix closing a finished cursor without supplying a callback
  • Loading branch information
brianc committed Dec 18, 2019
2 parents 3790609 + 124c89b commit e34c602
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
Expand Up @@ -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'
Expand Down
10 changes: 10 additions & 0 deletions test/close.js
Expand Up @@ -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)
Expand Down

0 comments on commit e34c602

Please sign in to comment.