Return promise on cursor end (#2589)

* Return promise on cursor end

* Remove redudant if
This commit is contained in:
Brian C 2021-07-29 17:17:15 -05:00 committed by GitHub
parent 92b4d37926
commit 98cd59e3e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 10 deletions

View File

@ -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

View File

@ -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)