框架
版本
Debouncer API 参考
Throttler API 参考
速率限制器 API 参考
队列 API 参考
批处理器 API 参考
批处理器示例

batch

函数:batch()

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

定义于:batcher.ts:247

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

类型参数

TValue

参数

fn

(items) => void

options

BatcherOptions<TValue>

返回

Function

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

参数

item

TValue

返回

void

示例

ts
const batchItems = batch<number>({
  batchSize: 3,
  processBatch: (items) => console.log('正在处理:', items)
});

batchItems(1);
batchItems(2);
batchItems(3); // 触发批处理
const batchItems = batch<number>({
  batchSize: 3,
  processBatch: (items) => console.log('正在处理:', items)
});

batchItems(1);
batchItems(2);
batchItems(3); // 触发批处理