* Try to get the next available document from the cursor or `null` if an empty batch is returned
()
| 584 | * Try to get the next available document from the cursor or `null` if an empty batch is returned |
| 585 | */ |
| 586 | async tryNext(): Promise<TSchema | null> { |
| 587 | this.signal?.throwIfAborted(); |
| 588 | |
| 589 | if (this.cursorId === Long.ZERO) { |
| 590 | throw new MongoCursorExhaustedError(); |
| 591 | } |
| 592 | |
| 593 | if (this.cursorOptions.timeoutMode === CursorTimeoutMode.ITERATION && this.cursorId != null) { |
| 594 | this.timeoutContext?.refresh(); |
| 595 | } |
| 596 | try { |
| 597 | let doc = this.documents?.shift(this.deserializationOptions); |
| 598 | if (doc != null) { |
| 599 | if (this.transform != null) return await this.transformDocument(doc); |
| 600 | return doc; |
| 601 | } |
| 602 | |
| 603 | await this.fetchBatch(); |
| 604 | |
| 605 | doc = this.documents?.shift(this.deserializationOptions); |
| 606 | if (doc != null) { |
| 607 | if (this.transform != null) return await this.transformDocument(doc); |
| 608 | return doc; |
| 609 | } |
| 610 | } finally { |
| 611 | if (this.cursorOptions.timeoutMode === CursorTimeoutMode.ITERATION) { |
| 612 | this.timeoutContext?.clear(); |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | return null; |
| 617 | } |
| 618 | |
| 619 | /** |
| 620 | * Iterates over all the documents for this cursor using the iterator, callback pattern. |
nothing calls this directly
no test coverage detected