Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/cursor/abstract_cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,16 @@ export type AbstractCursorEvents = {
[AbstractCursor.CLOSE](): void;
};

/** @public */
/**
* Base class for all cursors.
*
* A cursor does not support overlapping calls to any method that reads from the cursor, such as
* `hasNext()`, `next()` or `tryNext()`. Wait for each call to settle before making the next one on
* the same cursor. Calls that overlap can result in undefined behaviour, which could produce
* unpredictable or incorrect results.
*
* @public
*/
export abstract class AbstractCursor<
TSchema = any,
CursorEvents extends AbstractCursorEvents = AbstractCursorEvents
Expand Down Expand Up @@ -437,6 +446,12 @@ export abstract class AbstractCursor<
return readable;
}

/**
* Check if there is any document still available in the cursor.
*
* Do not call this method while a previous `hasNext()`, `next()` or `tryNext()` call on the same
* cursor is still pending. Overlapping calls are not supported.
*/
async hasNext(): Promise<boolean> {
this.signal?.throwIfAborted();

Expand All @@ -463,7 +478,12 @@ export abstract class AbstractCursor<
return false;
}

/** Get the next available document from the cursor, returns null if no more documents are available. */
/**
* Get the next available document from the cursor, returns null if no more documents are available.
*
* Do not call this method while a previous `hasNext()`, `next()` or `tryNext()` call on the same
* cursor is still pending. Overlapping calls are not supported.
*/
async next(): Promise<TSchema | null> {
this.signal?.throwIfAborted();

Expand Down Expand Up @@ -495,6 +515,9 @@ export abstract class AbstractCursor<

/**
* Try to get the next available document from the cursor or `null` if an empty batch is returned
*
* Do not call this method while a previous `hasNext()`, `next()` or `tryNext()` call on the same
* cursor is still pending. Overlapping calls are not supported.
*/
async tryNext(): Promise<TSchema | null> {
this.signal?.throwIfAborted();
Expand Down
Loading