Skip to content

Commit e34c602

Browse files
authored
Merge pull request #32 from hetul/fix-closing-finished-connections
Fix closing a finished cursor without supplying a callback
2 parents 3790609 + 124c89b commit e34c602

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Diff for: index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,11 @@ Cursor.prototype.end = util.deprecate(function(cb) {
175175

176176
Cursor.prototype.close = function(cb) {
177177
if (this.state === 'done') {
178-
return setImmediate(cb)
178+
if (cb) {
179+
return setImmediate(cb)
180+
} else {
181+
return
182+
}
179183
}
180184
this._closePortal()
181185
this.state = 'done'

Diff for: test/close.js

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ describe('close', function() {
1010
client.on('drain', client.end.bind(client))
1111
})
1212

13+
it('can close a finished cursor without a callback', function(done) {
14+
const cursor = new Cursor(text)
15+
this.client.query(cursor)
16+
this.client.query('SELECT NOW()', done)
17+
cursor.read(100, function(err) {
18+
assert.ifError(err)
19+
cursor.close()
20+
})
21+
})
22+
1323
it('closes cursor early', function(done) {
1424
const cursor = new Cursor(text)
1525
this.client.query(cursor)

0 commit comments

Comments
 (0)