Batcher docs: class example reads as a fixed window, but wait restarts on every addItem
维护者通常 1 天内回复
评估
- 难度
- 1/5
- 预计耗时
- 1 小时以内
- 新手友好度
- 88/100
- Issue 类型
- 文档
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- typescript
调研方向
阅读 Batcher 类参考文档及其 wait 选项文档,然后将它们的措辞与 batching 指南以及 issue 中描述的 addItem 定时器行为进行比较。更新类描述、选项文档和示例注释,说明定时器会在每个项目到达时重新启动,等待时间从最后一个项目之后开始。参考文档清楚地说明静默时间,且示例与之相符时,即为完成。
由索引模型根据 Issue 内容生成。
描述
TanStack Pacer version
@tanstack/pacer 0.23.0 (also checked 0.23.1 and main)
Framework/Library version
Framework-agnostic Batcher class; seen via @tanstack/react-pacer 0.24.0, React 19.3
Describe the bug and the steps to reproduce it
The Batcher class reference example says:
batcher.addItem(1);
batcher.addItem(2);
// After 2 seconds or when 5 items are added, whichever comes first,
// the batch will be processed
Read on its own, this suggests wait is a maximum delay measured from the first item. In the implementation, addItem clears and restarts the timer on every call (this.#clearTimeout() // clear any pending timeout to replace it with a new one), so wait measures quiet time since the last item. The batching guide does describe it that way ("executes a batch after no new items arrive for the configured duration"), but the class reference, where many people land first, does not. The example only adds two items at once, where both readings give the same result.
Under a steady stream with gaps shorter than wait, nothing is processed until the stream pauses or maxSize is reached:
import { Batcher } from '@tanstack/pacer'
const t0 = Date.now()
const b = new Batcher(
(items) => console.log(Date.now() - t0, 'ms:', items.length, 'items'),
{ wait: 100 },
)
let i = 0
const id = setInterval(() => {
b.addItem(i++)
if (i === 100) clearInterval(id)
}, 10)
// Logs once, ~1200 ms: 100 items. Nothing is processed during the first second.
Suggestion: in the class description and the wait option docs, state that the timer restarts on each addItem, and adjust the example comment, e.g. "2 seconds after the last item is added, or as soon as 5 items are collected, whichever comes first".
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)
The snippet above (Node, no framework, @tanstack/pacer 0.23.0).
Screenshots or Videos (Optional)
No response
Do you intend to try to help solve this bug with your own PR?
None
Terms & Code of Conduct
- I agree to follow this project's Code of Conduct
- I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
- 主要语言
- TypeScript
- 星标
- 793
- 派生
- 68
- 平均合并
- 18 小时 7 分钟
- 30 天内合并 PR
- 24
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
TanStack/pacer 的其他 Issue
-
replace deprecated Vitest spy assertion aliases可能已有人在做 @2yunseong 于 42 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
AsyncQueuer: concurrency > 1 not honoured for items added while another is executing (regression in 0.22.0)可能已有人在做 @KevinVandy 于 27 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 66/100
维护者通常 1 天内回复
-
Queued AsyncDebounce execution is silently dropped if it is executed after an in-flight run completes可能已有人在做 @SimenB 于 34 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 75/100
维护者通常 1 天内回复
-
Async utilities count swallowed retryer failures as successes and call onSuccess(undefined)可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 4/5 3-5 天 新手友好度 45/100
维护者通常 1 天内回复
-
debouncer.getAbortSignal() returns null due to maybeExecuteCount increment mismatch可能已有人在做 @SimenB 于 34 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 35/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 84/100
-
难度 2/5 1-3 小时 新手友好度 83/100
keptinventory/kept#336 ·
维护者通常 1 天内回复
-
good first issue
难度 2/5 1-3 小时 新手友好度 84/100
-
hemi-earn
难度 2/5 1-3 小时 新手友好度 72/100
vetro-protocol/vetro-monorepo#1013 ·
维护者通常 1 天内回复