@@ -27,8 +27,7 @@ import {
2727 type Disposable ,
2828 kDispose ,
2929 type MongoDBNamespace ,
30- squashError ,
31- throwIfAborted
30+ squashError
3231} from '../utils' ;
3332
3433/**
@@ -467,7 +466,7 @@ export abstract class AbstractCursor<
467466 }
468467
469468 async * [ Symbol . asyncIterator ] ( ) : AsyncGenerator < TSchema , void , void > {
470- throwIfAborted ( this . signal ) ;
469+ this . signal ?. throwIfAborted ( ) ;
471470
472471 if ( this . closed ) {
473472 return ;
@@ -495,7 +494,7 @@ export abstract class AbstractCursor<
495494 }
496495
497496 yield document ;
498- throwIfAborted ( this . signal ) ;
497+ this . signal ?. throwIfAborted ( ) ;
499498 }
500499 } finally {
501500 // Only close the cursor if it has not already been closed. This finally clause handles
@@ -541,7 +540,7 @@ export abstract class AbstractCursor<
541540 }
542541
543542 async hasNext ( ) : Promise < boolean > {
544- throwIfAborted ( this . signal ) ;
543+ this . signal ?. throwIfAborted ( ) ;
545544
546545 if ( this . cursorId === Long . ZERO ) {
547546 return false ;
@@ -568,7 +567,7 @@ export abstract class AbstractCursor<
568567
569568 /** Get the next available document from the cursor, returns null if no more documents are available. */
570569 async next ( ) : Promise < TSchema | null > {
571- throwIfAborted ( this . signal ) ;
570+ this . signal ?. throwIfAborted ( ) ;
572571
573572 if ( this . cursorId === Long . ZERO ) {
574573 throw new MongoCursorExhaustedError ( ) ;
@@ -600,7 +599,7 @@ export abstract class AbstractCursor<
600599 * Try to get the next available document from the cursor or `null` if an empty batch is returned
601600 */
602601 async tryNext ( ) : Promise < TSchema | null > {
603- throwIfAborted ( this . signal ) ;
602+ this . signal ?. throwIfAborted ( ) ;
604603
605604 if ( this . cursorId === Long . ZERO ) {
606605 throw new MongoCursorExhaustedError ( ) ;
@@ -641,7 +640,7 @@ export abstract class AbstractCursor<
641640 * @deprecated - Will be removed in a future release. Use for await...of instead.
642641 */
643642 async forEach ( iterator : ( doc : TSchema ) => boolean | void ) : Promise < void > {
644- throwIfAborted ( this . signal ) ;
643+ this . signal ?. throwIfAborted ( ) ;
645644
646645 if ( typeof iterator !== 'function' ) {
647646 throw new MongoInvalidArgumentError ( 'Argument "iterator" must be a function' ) ;
@@ -668,7 +667,7 @@ export abstract class AbstractCursor<
668667 * cursor.rewind() can be used to reset the cursor.
669668 */
670669 async toArray ( ) : Promise < TSchema [ ] > {
671- throwIfAborted ( this . signal ) ;
670+ this . signal ?. throwIfAborted ( ) ;
672671
673672 const array : TSchema [ ] = [ ] ;
674673 // at the end of the loop (since readBufferedDocuments is called) the buffer will be empty
0 commit comments