框架
版本
防抖器 API 参考
节流器 API 参考
速率限制器 API 参考
队列 API 参考
批处理器 API 参考

批处理

函数: batch()

ts
function batch<TValue>(fn, options): (item) => void
function batch<TValue>(fn, options): (item) => void

定义于: batcher.ts:305

创建一个处理批处理项目的批处理器

类型参数

TValue

参数

fn

(items) => void

options

BatcherOptions<TValue>

Returns (返回)

Function

向批处理器添加一个项目。如果达到批处理大小、发生超时或 shouldProcess 返回 true,则将处理该批处理。

参数

item

TValue

Returns (返回)

void

示例

ts
const batchItems = batch<number>(
  (items) => console.log('Processing:', items),
  {
    maxSize: 3,
    onExecute: (batch, batcher) => console.log('Batch executed:', batch)
  }
);

batchItems(1);
batchItems(2);
batchItems(3); // Triggers batch processing
const batchItems = batch<number>(
  (items) => console.log('Processing:', items),
  {
    maxSize: 3,
    onExecute: (batch, batcher) => console.log('Batch executed:', batch)
  }
);

batchItems(1);
batchItems(2);
batchItems(3); // Triggers batch processing
我们的合作伙伴
Code Rabbit
Unkey
订阅 Bytes

您的每周 JavaScript 资讯。每周一免费发送给超过 10 万开发者。

Bytes

无垃圾邮件。您可以随时取消订阅。

订阅 Bytes

您的每周 JavaScript 资讯。每周一免费发送给超过 10 万开发者。

Bytes

无垃圾邮件。您可以随时取消订阅。