@@ -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 ++ )
@@ -45,19 +58,12 @@ Cursor.prototype.submit = function (connection) {
45
58
46
59
con . flush ( )
47
60
48
- const ifNoData = ( ) => {
49
- this . state = 'idle'
50
- this . _shiftQueue ( )
51
- }
52
-
53
61
if ( this . _conf . types ) {
54
62
this . _result . _getTypeParser = this . _conf . types . getTypeParser
55
63
}
56
64
57
- con . once ( 'noData' , ifNoData )
58
- con . once ( 'rowDescription' , ( ) => {
59
- con . removeListener ( 'noData' , ifNoData )
60
- } )
65
+ con . once ( 'noData' , this . _ifNoData )
66
+ con . once ( 'rowDescription' , this . _rowDescription )
61
67
}
62
68
63
69
Cursor . prototype . _shiftQueue = function ( ) {
@@ -114,6 +120,8 @@ Cursor.prototype.handleEmptyQuery = function () {
114
120
}
115
121
116
122
Cursor . prototype . handleError = function ( msg ) {
123
+ this . connection . removeListener ( 'noData' , this . _ifNoData )
124
+ this . connection . removeListener ( 'rowDescription' , this . _rowDescription )
117
125
this . state = 'error'
118
126
this . _error = msg
119
127
// satisfy any waiting callback
0 commit comments