File tree 2 files changed +31
-0
lines changed
2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -237,6 +237,10 @@ const hasNext = (self, callback) => {
237
237
return callback ( null , true ) ;
238
238
}
239
239
240
+ if ( self . isNotified ( ) ) {
241
+ return callback ( null , false ) ;
242
+ }
243
+
240
244
nextObject ( self , function ( err , doc ) {
241
245
if ( err ) return callback ( err , null ) ;
242
246
if ( self . s . state === Cursor . CLOSED || self . isDead ( ) ) return callback ( null , false ) ;
Original file line number Diff line number Diff line change @@ -4396,4 +4396,31 @@ describe('Cursor', function() {
4396
4396
cursor . close ( ( ) => client . close ( ( ) => done ( ) ) ) ;
4397
4397
} ) ;
4398
4398
} ) ;
4399
+
4400
+ it ( 'should return false when exhausted and hasNext called more than once' , function ( done ) {
4401
+ const configuration = this . configuration ;
4402
+ const client = configuration . newClient ( { w : 1 } , { poolSize : 1 , auto_reconnect : false } ) ;
4403
+
4404
+ client . connect ( function ( err , client ) {
4405
+ const db = client . db ( configuration . db ) ;
4406
+
4407
+ db . createCollection ( 'cursor_hasNext_test' ) . then ( function ( ) {
4408
+ const cursor = db . collection ( 'cursor_hasNext_test' ) . find ( ) ;
4409
+
4410
+ cursor
4411
+ . hasNext ( )
4412
+ . then ( function ( val1 ) {
4413
+ expect ( val1 ) . to . equal ( false ) ;
4414
+ return cursor . hasNext ( ) ;
4415
+ } )
4416
+ . then ( function ( val2 ) {
4417
+ expect ( val2 ) . to . equal ( false ) ;
4418
+ cursor . close ( ( ) => client . close ( ( ) => done ( ) ) ) ;
4419
+ } )
4420
+ . catch ( err => {
4421
+ cursor . close ( ( ) => client . close ( ( ) => done ( err ) ) ) ;
4422
+ } ) ;
4423
+ } ) ;
4424
+ } ) ;
4425
+ } ) ;
4399
4426
} ) ;
You can’t perform that action at this time.
0 commit comments