File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 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 {
171171 }
172172 // dispatch error to all waiting callbacks
173173 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 )
175176 }
177+ this . _queue . length = 0
176178
177179 if ( this . listenerCount ( 'error' ) > 0 ) {
178180 // 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 () {
1919 } )
2020 } )
2121 } )
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+ } )
2239} )
2340
2441describe ( 'read callback does not fire sync' , ( ) => {
You can’t perform that action at this time.
0 commit comments