@@ -17,7 +17,6 @@ import { TODO_NODE_3286, TypedEventEmitter } from '../mongo_types';
1717import { executeOperation , ExecutionResult } from '../operations/execute_operation' ;
1818import { GetMoreOperation } from '../operations/get_more' ;
1919import { KillCursorsOperation } from '../operations/kill_cursors' ;
20- import { PromiseProvider } from '../promise_provider' ;
2120import { ReadConcern , ReadConcernLike } from '../read_concern' ;
2221import { ReadPreference , ReadPreferenceLike } from '../read_preference' ;
2322import type { Server } from '../sdam/server' ;
@@ -297,47 +296,36 @@ export abstract class AbstractCursor<
297296 return bufferedDocs ;
298297 }
299298
300- [ Symbol . asyncIterator ] ( ) : AsyncIterator < TSchema , void > {
301- async function * nativeAsyncIterator ( this : AbstractCursor < TSchema > ) {
302- if ( this . closed ) {
303- return ;
304- }
299+ async * [ Symbol . asyncIterator ] ( ) : AsyncIterator < TSchema , void > {
300+ if ( this . closed ) {
301+ return ;
302+ }
305303
306- while ( true ) {
307- const document = await this . next ( ) ;
304+ while ( true ) {
305+ const document = await this . next ( ) ;
308306
309- // Intentional strict null check, because users can map cursors to falsey values.
310- // We allow mapping to all values except for null.
311- // eslint-disable-next-line no-restricted-syntax
312- if ( document === null ) {
313- if ( ! this . closed ) {
314- const message =
315- 'Cursor returned a `null` document, but the cursor is not exhausted. Mapping documents to `null` is not supported in the cursor transform.' ;
307+ // Intentional strict null check, because users can map cursors to falsey values.
308+ // We allow mapping to all values except for null.
309+ // eslint-disable-next-line no-restricted-syntax
310+ if ( document === null ) {
311+ if ( ! this . closed ) {
312+ const message =
313+ 'Cursor returned a `null` document, but the cursor is not exhausted. Mapping documents to `null` is not supported in the cursor transform.' ;
316314
317- await cleanupCursorAsync ( this , { needsToEmitClosed : true } ) . catch ( ( ) => null ) ;
315+ await cleanupCursorAsync ( this , { needsToEmitClosed : true } ) . catch ( ( ) => null ) ;
318316
319- throw new MongoAPIError ( message ) ;
320- }
321- break ;
322- }
323-
324- yield document ;
325-
326- if ( this [ kId ] === Long . ZERO ) {
327- // Cursor exhausted
328- break ;
317+ throw new MongoAPIError ( message ) ;
329318 }
319+ break ;
330320 }
331- }
332321
333- const iterator = nativeAsyncIterator . call ( this ) ;
322+ yield document ;
334323
335- if ( PromiseProvider . get ( ) == null ) {
336- return iterator ;
324+ if ( this [ kId ] === Long . ZERO ) {
325+ // Cursor exhausted
326+ break ;
327+ }
337328 }
338- return {
339- next : ( ) => maybeCallback ( ( ) => iterator . next ( ) , null )
340- } ;
341329 }
342330
343331 stream ( options ?: CursorStreamOptions ) : Readable & AsyncIterable < TSchema > {
0 commit comments