File tree 2 files changed +20
-1
lines changed
2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -171,8 +171,10 @@ class Cursor extends EventEmitter {
171
171
}
172
172
// dispatch error to all waiting callbacks
173
173
for ( let i = 0 ; i < this . _queue . length ; i ++ ) {
174
- this . _queue . pop ( ) [ 1 ] ( msg )
174
+ const queuedCallback = this . _queue [ i ] [ 1 ]
175
+ queuedCallback . call ( this , msg )
175
176
}
177
+ this . _queue . length = 0
176
178
177
179
if ( this . listenerCount ( 'error' ) > 0 ) {
178
180
// only dispatch error events if we have a listener
Original file line number Diff line number Diff line change @@ -19,6 +19,23 @@ describe('error handling', function () {
19
19
} )
20
20
} )
21
21
} )
22
+
23
+ it ( 'errors queued reads' , async ( ) => {
24
+ const client = new pg . Client ( )
25
+ await client . connect ( )
26
+
27
+ const cursor = client . query ( new Cursor ( 'asdfdffsdf' ) )
28
+
29
+ const immediateRead = cursor . read ( 1 )
30
+ const queuedRead1 = cursor . read ( 1 )
31
+ const queuedRead2 = cursor . read ( 1 )
32
+
33
+ assert ( await immediateRead . then ( ( ) => null , ( err ) => err ) )
34
+ assert ( await queuedRead1 . then ( ( ) => null , ( err ) => err ) )
35
+ assert ( await queuedRead2 . then ( ( ) => null , ( err ) => err ) )
36
+
37
+ client . end ( )
38
+ } )
22
39
} )
23
40
24
41
describe ( 'read callback does not fire sync' , ( ) => {
You can’t perform that action at this time.
0 commit comments