Skip to content

Commit e20d012

Browse files
committed
Merge branch 'master' of https://github.com/juneidysoo/node-pg-cursor into juneidysoo-master
2 parents e34c602 + b0f7958 commit e20d012

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

index.js

+17-9
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,23 @@ function Cursor(text, values, config) {
1919
this._cb = null
2020
this._rows = null
2121
this._portal = null
22+
this._ifNoData = this._ifNoData.bind(this)
23+
this._rowDescription = this._rowDescription.bind(this)
2224
}
2325

2426
util.inherits(Cursor, EventEmitter)
2527

28+
Cursor.prototype._ifNoData = function() {
29+
this.state = 'idle'
30+
this._shiftQueue()
31+
}
32+
33+
Cursor.prototype._rowDescription = function() {
34+
if (this.connection) {
35+
this.connection.removeListener('noData', this._ifNoData)
36+
}
37+
}
38+
2639
Cursor.prototype.submit = function(connection) {
2740
this.connection = connection
2841
this._portal = 'C_' + nextUniqueID++
@@ -54,19 +67,12 @@ Cursor.prototype.submit = function(connection) {
5467

5568
con.flush()
5669

57-
const ifNoData = () => {
58-
this.state = 'idle'
59-
this._shiftQueue()
60-
}
61-
6270
if (this._conf.types) {
6371
this._result._getTypeParser = this._conf.types.getTypeParser
6472
}
6573

66-
con.once('noData', ifNoData)
67-
con.once('rowDescription', () => {
68-
con.removeListener('noData', ifNoData)
69-
})
74+
con.once('noData', this._ifNoData)
75+
con.once('rowDescription', this._rowDescription)
7076
}
7177

7278
Cursor.prototype._shiftQueue = function() {
@@ -132,6 +138,8 @@ Cursor.prototype.handleEmptyQuery = function() {
132138
}
133139

134140
Cursor.prototype.handleError = function(msg) {
141+
this.connection.removeListener('noData', this._ifNoData)
142+
this.connection.removeListener('rowDescription', this._rowDescription)
135143
this.state = 'error'
136144
this._error = msg
137145
// satisfy any waiting callback

0 commit comments

Comments
 (0)