본문으로 건너뛰기

함수: injectAsyncBatchedCallback()

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

정의 위치: angular-pacer/src/async-batcher/injectAsyncBatchedCallback.ts:42

콜백 함수의 비동기 배칭 버전을 생성하는 Angular 함수입니다. 이 함수는 injectAsyncBatcher를 래핑하여 기본 비동기 배칭 요구 사항에 맞는 간소화된 API를 제공하는 래퍼입니다.

배칭된 함수는 항목을 모은 다음 구성된 조건(maxSize, 대기 시간 등)에 따라 비동기 배치로 처리합니다.

이 함수는 injectAsyncBatcher보다 간단한 API를 제공하므로 기본 비동기 배칭에 적합합니다. 하지만 내부 AsyncBatcher 인스턴스를 노출하지 않습니다.

다음과 같은 기능이 필요한 고급 사용 사례에서는:

  • 수동 플러시
  • 배치 상태 확인
  • 오류 처리 콜백
  • 재시도 지원

대신 injectAsyncBatcher 함수 사용을 고려합니다.

타입 매개변수

TValue

TValue

매개변수

fn

(items) => Promise&lt;any>

options

AsyncBatcherOptions&lt;TValue>

반환값

(item): Promise<void>;

매개변수

item

TValue

반환값

Promise&lt;void>

예시

// Batch async API calls
const batchApiCall = injectAsyncBatchedCallback(
async (items: Array<Data>) => {
const response = await fetch('/api/batch', {
method: 'POST',
body: JSON.stringify(items)
});
return response.json();
},
{ maxSize: 10, wait: 1000 }
);

// Items will be batched and sent together
await batchApiCall(data1);
await batchApiCall(data2);