mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Return promise on cursor end (#2589)
* Return promise on cursor end * Remove redudant if
This commit is contained in:
parent
92b4d37926
commit
98cd59e3e7
@ -208,20 +208,15 @@ class Cursor extends EventEmitter {
|
||||
}
|
||||
|
||||
if (!this.connection || this.state === 'done') {
|
||||
if (cb) {
|
||||
return setImmediate(cb)
|
||||
} else {
|
||||
return
|
||||
}
|
||||
setImmediate(cb)
|
||||
return promise
|
||||
}
|
||||
|
||||
this._closePortal()
|
||||
this.state = 'done'
|
||||
if (cb) {
|
||||
this.connection.once('readyForQuery', function () {
|
||||
cb()
|
||||
})
|
||||
}
|
||||
this.connection.once('readyForQuery', function () {
|
||||
cb()
|
||||
})
|
||||
|
||||
// Return the promise (or undefined)
|
||||
return promise
|
||||
|
||||
@ -23,6 +23,17 @@ describe('close', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('can close a finished cursor a promise', function (done) {
|
||||
const cursor = new Cursor(text)
|
||||
this.client.query(cursor)
|
||||
cursor.read(100, (err) => {
|
||||
assert.ifError(err)
|
||||
cursor.close().then(() => {
|
||||
this.client.query('SELECT NOW()', done)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('closes cursor early', function (done) {
|
||||
const cursor = new Cursor(text)
|
||||
this.client.query(cursor)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user