Skip to content

Commit 24e485e

Browse files
author
Hetul Patel
committed
Fix closing a finished cursor without supplying a callback
1 parent c0f5518 commit 24e485e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ Cursor.prototype.end = function (cb) {
149149

150150
Cursor.prototype.close = function (cb) {
151151
if (this.state === 'done') {
152-
return setImmediate(cb)
152+
if (cb) {
153+
return setImmediate(cb)
154+
} else {
155+
return
156+
}
153157
}
154158
this.connection.close({type: 'P'})
155159
this.connection.sync()

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+
var cursor = new Cursor(text)
15+
this.client.query(cursor)
16+
this.client.query('SELECT NOW()', done)
17+
cursor.read(100, function (err, res) {
18+
assert.ifError(err)
19+
cursor.close()
20+
})
21+
})
22+
1323
it('closes cursor early', function (done) {
1424
var cursor = new Cursor(text)
1525
this.client.query(cursor)

0 commit comments

Comments
 (0)