Skip to content

Commit a4a4c47

Browse files
committed
Drain cursors when killed
1 parent a993de1 commit a4a4c47

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ This driver uses semantic versioning:
1616

1717
## [Unreleased]
1818

19+
### Changed
20+
21+
- Killing a cursor now also drains it locally
22+
1923
### Fixed
2024

2125
- Fixed a potential memory leak in cursor batch handling

src/cursor.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,9 +601,9 @@ export class BatchedArrayCursor<T = any> {
601601
}
602602

603603
/**
604-
* Kills the cursor and frees up associated database resources.
604+
* Drains the cursor and frees up associated database resources.
605605
*
606-
* This method has no effect if all batches have already been fetched.
606+
* This method has no effect if all batches have already been consumed.
607607
*
608608
* @example
609609
* ```js
@@ -620,6 +620,12 @@ export class BatchedArrayCursor<T = any> {
620620
* ```
621621
*/
622622
async kill(): Promise<void> {
623+
if (this._batches.length) {
624+
for (const batch of this._batches.values()) {
625+
batch.clear();
626+
}
627+
this._batches.clear();
628+
}
623629
if (!this.hasNext) return undefined;
624630
return this._db.request(
625631
{

0 commit comments

Comments
 (0)