Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Batcher docs: class example reads as a fixed window, but wait restarts on every addItem

未关闭 适合新手
#289 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@MFA-G 已经在做这个了。

开始于 2026年10月11日。

  • #290 来自 @MFA-G —— 未关闭

评估

难度
1/5
预计耗时
1 小时以内
新手友好度
88/100
Issue 类型
文档
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript
领域
documentation

调研方向

阅读 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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TanStack/pacer 的其他 Issue

查看 TanStack/pacer 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。