MCPcopy
hub / github.com/mongodb/node-mongodb-native / [Symbol.asyncIterator]

Function [Symbol.asyncIterator]

src/cursor/abstract_cursor.ts:470–513  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

468 }
469
470 async *[Symbol.asyncIterator](): AsyncGenerator<TSchema, void, void> {
471 this.signal?.throwIfAborted();
472
473 if (this.closed) {
474 return;
475 }
476
477 try {
478 while (true) {
479 if (this.isKilled) {
480 return;
481 }
482
483 if (this.closed) {
484 return;
485 }
486
487 if (this.cursorId != null && this.isDead && (this.documents?.length ?? 0) === 0) {
488 return;
489 }
490
491 const document = await this.next();
492
493 // eslint-disable-next-line no-restricted-syntax
494 if (document === null) {
495 return;
496 }
497
498 yield document;
499
500 this.signal?.throwIfAborted();
501 }
502 } finally {
503 // Only close the cursor if it has not already been closed. This finally clause handles
504 // the case when a user would break out of a for await of loop early.
505 if (!this.isClosed) {
506 try {
507 await this.close();
508 } catch (error) {
509 squashError(error);
510 }
511 }
512 }
513 }
514
515 stream(): Readable & AsyncIterable<TSchema> {
516 const readable = new ReadableCursorStream(this);

Callers

nothing calls this directly

Calls 4

squashErrorFunction · 0.90
throwIfAbortedMethod · 0.80
nextMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected