@@ -17,7 +17,6 @@ import { TODO_NODE_3286, TypedEventEmitter } from '../mongo_types';
17
17
import { executeOperation , ExecutionResult } from '../operations/execute_operation' ;
18
18
import { GetMoreOperation } from '../operations/get_more' ;
19
19
import { KillCursorsOperation } from '../operations/kill_cursors' ;
20
- import { PromiseProvider } from '../promise_provider' ;
21
20
import { ReadConcern , ReadConcernLike } from '../read_concern' ;
22
21
import { ReadPreference , ReadPreferenceLike } from '../read_preference' ;
23
22
import type { Server } from '../sdam/server' ;
@@ -297,47 +296,36 @@ export abstract class AbstractCursor<
297
296
return bufferedDocs ;
298
297
}
299
298
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
+ }
305
303
306
- while ( true ) {
307
- const document = await this . next ( ) ;
304
+ while ( true ) {
305
+ const document = await this . next ( ) ;
308
306
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.' ;
316
314
317
- await cleanupCursorAsync ( this , { needsToEmitClosed : true } ) . catch ( ( ) => null ) ;
315
+ await cleanupCursorAsync ( this , { needsToEmitClosed : true } ) . catch ( ( ) => null ) ;
318
316
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 ) ;
329
318
}
319
+ break ;
330
320
}
331
- }
332
321
333
- const iterator = nativeAsyncIterator . call ( this ) ;
322
+ yield document ;
334
323
335
- if ( PromiseProvider . get ( ) == null ) {
336
- return iterator ;
324
+ if ( this [ kId ] === Long . ZERO ) {
325
+ // Cursor exhausted
326
+ break ;
327
+ }
337
328
}
338
- return {
339
- next : ( ) => maybeCallback ( ( ) => iterator . next ( ) , null )
340
- } ;
341
329
}
342
330
343
331
stream ( options ?: CursorStreamOptions ) : Readable & AsyncIterable < TSchema > {
0 commit comments