File tree 2 files changed +16
-10
lines changed
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 {
208
208
}
209
209
210
210
if ( ! this . connection || this . state === 'done' ) {
211
- if ( cb ) {
212
- return setImmediate ( cb )
213
- } else {
214
- return
215
- }
211
+ setImmediate ( cb )
212
+ return promise
216
213
}
217
214
218
215
this . _closePortal ( )
219
216
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
+ } )
225
220
226
221
// Return the promise (or undefined)
227
222
return promise
Original file line number Diff line number Diff line change @@ -23,6 +23,17 @@ describe('close', function () {
23
23
} )
24
24
} )
25
25
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
+
26
37
it ( 'closes cursor early' , function ( done ) {
27
38
const cursor = new Cursor ( text )
28
39
this . client . query ( cursor )
You can’t perform that action at this time.
0 commit comments