본문으로 건너뛰기

throttle()

function throttle<T>(config): AnyFunc<T>

throttle 효과가 적용된 function 을 생성합니다.

options 로 함수의 호출 시점을 지정 할 수 있습니다. "leading" 일 경우 함수를 즉시 호출하고, 지연 시간동안 추가적인 호출을 차단합니다. "trailing" 일 경우 지연 시간이 모두 흐른 뒤에 함수가 호출 됩니다.

Type Parameters

Type ParameterDescription
T extends unknown[]쓰로틀링될 함수의 파라미터 타입입니다.

Parameters

ParameterTypeDescription
configConfig<T>throttle 설정 객체

Returns

AnyFunc<T>

throttle 처리 된 함수

Example

const throttled_func = throttle({
func: (x: number, y: number) => {
console.log(`throttled: x=${x}, y=${y}`);
},
wait: 1000,
options: { leading: true, trailing: true },
});

throttled_func(1, 2);
throttled_func(3, 4);
throttled_func(5, 6);