본문으로 건너뛰기

함수: batch()

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

정의 위치: batcher.ts:323

항목을 배치 단위로 처리하는 배처를 생성합니다.

이 동기 버전은 더 가벼워 대부분의 경우 충분합니다. 프로미스, 재시도 지원, 중단/취소 기능 또는 고급 오류 처리가 필요하면 asyncBatch로 전환합니다.

타입 매개변수

TValue

TValue

매개변수

fn

(items) => void

options

BatcherOptions&lt;TValue>

반환값

(item): void;

배처에 항목을 추가합니다. 배치 크기에 도달하거나 타임아웃이 발생하거나 shouldProcess가 true를 반환하면 배치를 처리합니다.

매개변수

item

TValue

반환값

void

예시

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