mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Merge pull request #32 from hetul/fix-closing-finished-connections
Fix closing a finished cursor without supplying a callback
This commit is contained in:
commit
e34c6021ef
6
index.js
6
index.js
@ -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'
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user