@@ -19,10 +19,23 @@ function Cursor(text, values, config) {
19
19
this . _cb = null
20
20
this . _rows = null
21
21
this . _portal = null
22
+ this . _ifNoData = this . _ifNoData . bind ( this )
23
+ this . _rowDescription = this . _rowDescription . bind ( this )
22
24
}
23
25
24
26
util . inherits ( Cursor , EventEmitter )
25
27
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
+
26
39
Cursor . prototype . submit = function ( connection ) {
27
40
this . connection = connection
28
41
this . _portal = 'C_' + nextUniqueID ++
@@ -54,19 +67,12 @@ Cursor.prototype.submit = function(connection) {
54
67
55
68
con . flush ( )
56
69
57
- const ifNoData = ( ) => {
58
- this . state = 'idle'
59
- this . _shiftQueue ( )
60
- }
61
-
62
70
if ( this . _conf . types ) {
63
71
this . _result . _getTypeParser = this . _conf . types . getTypeParser
64
72
}
65
73
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 )
70
76
}
71
77
72
78
Cursor . prototype . _shiftQueue = function ( ) {
@@ -132,6 +138,8 @@ Cursor.prototype.handleEmptyQuery = function() {
132
138
}
133
139
134
140
Cursor . prototype . handleError = function ( msg ) {
141
+ this . connection . removeListener ( 'noData' , this . _ifNoData )
142
+ this . connection . removeListener ( 'rowDescription' , this . _rowDescription )
135
143
this . state = 'error'
136
144
this . _error = msg
137
145
// satisfy any waiting callback
0 commit comments