()
| 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); |
nothing calls this directly
no test coverage detected