Skip to content

Commit 2431a63

Browse files
authored
Merge pull request #2042 from brianc/bmc/callback-on-ready
Fire close callback when ready for next query
2 parents 47af4e8 + 5a6166d commit 2431a63

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Diff for: packages/pg-cursor/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const util = require('util')
66

77
let nextUniqueID = 1 // concept borrowed from org.postgresql.core.v3.QueryExecutorImpl
88

9-
function Cursor (text, values, config) {
9+
function Cursor(text, values, config) {
1010
EventEmitter.call(this)
1111

1212
this._conf = config || {}
@@ -192,7 +192,7 @@ Cursor.prototype.close = function (cb) {
192192
this._closePortal()
193193
this.state = 'done'
194194
if (cb) {
195-
this.connection.once('closeComplete', function () {
195+
this.connection.once('readyForQuery', function () {
196196
cb()
197197
})
198198
}

Diff for: packages/pg-cursor/test/close.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ describe('close', function () {
77
beforeEach(function (done) {
88
const client = (this.client = new pg.Client())
99
client.connect(done)
10-
client.on('drain', client.end.bind(client))
10+
})
11+
12+
this.afterEach(function (done) {
13+
this.client.end(done)
1114
})
1215

1316
it('can close a finished cursor without a callback', function (done) {
@@ -34,8 +37,9 @@ describe('close', function () {
3437
const cursor = new Cursor(text)
3538
const client = this.client
3639
client.query(cursor)
37-
cursor.read(25, function (err) {
40+
cursor.read(25, function (err, rows) {
3841
assert.ifError(err)
42+
assert.strictEqual(rows.length, 25)
3943
cursor.close(function (err) {
4044
assert.ifError(err)
4145
client.query('SELECT NOW()', done)

0 commit comments

Comments
 (0)