File tree Expand file tree Collapse file tree 2 files changed +16
-10
lines changed Expand file tree Collapse file tree 2 files changed +16
-10
lines changed Original file line number Diff line number Diff line change @@ -208,20 +208,15 @@ class Cursor extends EventEmitter {
208208 }
209209
210210 if ( ! this . connection || this . state === 'done' ) {
211- if ( cb ) {
212- return setImmediate ( cb )
213- } else {
214- return
215- }
211+ setImmediate ( cb )
212+ return promise
216213 }
217214
218215 this . _closePortal ( )
219216 this . state = 'done'
220- if ( cb ) {
221- this . connection . once ( 'readyForQuery' , function ( ) {
222- cb ( )
223- } )
224- }
217+ this . connection . once ( 'readyForQuery' , function ( ) {
218+ cb ( )
219+ } )
225220
226221 // Return the promise (or undefined)
227222 return promise
Original file line number Diff line number Diff line change @@ -23,6 +23,17 @@ describe('close', function () {
2323 } )
2424 } )
2525
26+ it ( 'can close a finished cursor a promise' , function ( done ) {
27+ const cursor = new Cursor ( text )
28+ this . client . query ( cursor )
29+ cursor . read ( 100 , ( err ) => {
30+ assert . ifError ( err )
31+ cursor . close ( ) . then ( ( ) => {
32+ this . client . query ( 'SELECT NOW()' , done )
33+ } )
34+ } )
35+ } )
36+
2637 it ( 'closes cursor early' , function ( done ) {
2738 const cursor = new Cursor ( text )
2839 this . client . query ( cursor )
You can’t perform that action at this time.
0 commit comments