Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
20 changes: 20 additions & 0 deletions src/change_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,26 @@ export class ChangeStream<
}, callback);
}

async *[Symbol.asyncIterator](): AsyncGenerator<TChange, void, void> {
if (this.closed) {
return;
}

try {
// Change streams run indefinitely as long as errors are resumable
// So the only loop breaking condition is if `next()` throws
while (true) {
yield await this.next();
}
} finally {
try {
await this.close();
} catch {
// we're not concerned with errors from close()
}
}
}

/** Is the cursor closed */
get closed(): boolean {
return this[kClosed] || this.cursor.closed;
Expand Down
Loading