Repository navigation
feat(batch): add pendingCount, flush(), and clear() lifecycle helpers - #12
Divyanshgupta2580 wants to merge 1 commit into
Conversation
Confidence Score: 4/5
[Medium impact] The changes affect callers managing queued BatchFlight work. The PR appears safe to merge, with non-blocking improvements to tests and documentation. FindingsFix with agent prompt### Issue 1
test/batch.test.ts:349-356
The new `clear()` test never checks that its timer was removed. Both promise assertions finish before the 5-second window ends. `called` stays false even if the timer later fires because the queue is already empty.
Use fake timers and assert that no timer remains after `clear()`. Cover the same cleanup after public `flush()`. Otherwise, a change that leaves Node.js running unnecessarily would pass these tests.
### Issue 2
src/batch.ts:205-209
The public API references in `README.md` and `llms.txt` still list only `load()` and `loadMany()`. Add `pendingCount`, `flush()`, and `clear()` there. Explain that they only affect queued keys, that `flush()` does not wait for completion, and that `clear()` returns a unique-key count. These details matter for the shutdown use case this change adds.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryAdds three queue helpers to
No blocking behavior issue was found. Non-blocking feedback covers timer-cleanup tests and API documentation. Reviews (1) · Last reviewed commit: "feat(batch): add pendingCount, flush(), ..." · Reviewed by Greptile |
| it('clear() cancels active timer, rejects pending waiters, and returns cleared count', async () => { | ||
| let called = false; | ||
| const batch = new BatchFlight<number, string>( | ||
| async (keys) => { | ||
| called = true; | ||
| return keys.map((k) => `val:${k}`); | ||
| }, | ||
| { maxWindowMs: 5_000 }, |
There was a problem hiding this comment.
The new clear() test never checks that its timer was removed. Both promise assertions finish before the 5-second window ends. called stays false even if the timer later fires because the queue is already empty.
Use fake timers and assert that no timer remains after clear(). Cover the same cleanup after public flush(). Otherwise, a change that leaves Node.js running unnecessarily would pass these tests.
Prompt To Fix With AI
This is a comment left during a code review.
Path: test/batch.test.ts
Line: 349-356
Comment:
**Timer cleanup goes unchecked**
The new `clear()` test never checks that its timer was removed. Both promise assertions finish before the 5-second window ends. `called` stays false even if the timer later fires because the queue is already empty.
Use fake timers and assert that no timer remains after `clear()`. Cover the same cleanup after public `flush()`. Otherwise, a change that leaves Node.js running unnecessarily would pass these tests.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| /** | ||
| * Cancels any active flush timer and rejects all currently pending waiters | ||
| * with `reason`, returning the number of cleared entries. | ||
| */ | ||
| clear(reason?: unknown): number { |
There was a problem hiding this comment.
API references omit new helpers
The public API references in README.md and llms.txt still list only load() and loadMany(). Add pendingCount, flush(), and clear() there. Explain that they only affect queued keys, that flush() does not wait for completion, and that clear() returns a unique-key count. These details matter for the shutdown use case this change adds.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/batch.ts
Line: 205-209
Comment:
**API references omit new helpers**
The public API references in `README.md` and `llms.txt` still list only `load()` and `loadMany()`. Add `pendingCount`, `flush()`, and `clear()` there. Explain that they only affect queued keys, that `flush()` does not wait for completion, and that `clear()` returns a unique-key count. These details matter for the shutdown use case this change adds.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Closes #7
Added
get pendingCount(), madeflush()public, and addedclear(reason?)toBatchFlightinsrc/batch.tsso callers can inspect queued keys, drain batches early, or cancel pending waiters during shutdown. Added unit tests intest/batch.test.tscovering both normal queuing and empty-queue calls.Tested locally with
npm run build && npm test && npm run check:types(84/84 tests passed andpublintreported no problems).