함수: injectAsyncThrottledCallback()
function injectAsyncThrottledCallback<TFn>(fn, options): (...args) => Promise<Awaited<ReturnType<TFn>> | undefined>;
정의 위치: angular-pacer/src/async-throttler/injectAsyncThrottledCallback.ts:41
콜백 함수의 비동기 스로틀 버전을 생성하는 Angular 함수입니다.
이 함수는 injectAsyncThrottler를 래핑하여 기본 비동기 스로틀 요구 사항에 맞는 간소화된 API를 제공하는
래퍼입니다.
스로틀된 함수는 지정된 대기 시간 안에 최대 한 번 실행됩니다.
이 함수는 injectAsyncThrottler보다 간단한 API를 제공하므로 기본
비동기 스로틀에 적합합니다. 하지만 내부 AsyncThrottler 인스턴스를 노출하지 않습니다.
다음과 같은 기능이 필요한 고급 사용 사례에서는:
- 수동 취소
- 실행 횟수 확인
- 오류 처리 콜백
- 재시도 지원
대신 injectAsyncThrottler 함수 사용을 고려합니다.
타입 매개변수
TFn
TFn extends AnyAsyncFunction
매개변수
fn
TFn
options
AsyncThrottlerOptions<TFn>
반환값
(...args): Promise<Awaited<ReturnType<TFn>> | undefined>;
매개변수
args
...Parameters<TFn>
반환값
Promise<Awaited<ReturnType<TFn>> | undefined>
예시
// Throttle an async update handler
const handleUpdate = injectAsyncThrottledCallback(
async (data: Data) => {
const response = await fetch('/api/update', {
method: 'POST',
body: JSON.stringify(data)
});
return response.json();
},
{ wait: 1000 }
);
// Use in an event handler
const result = await handleUpdate(updateData);