Skip to content

throttle

Creates a throttled function that only invokes func at most once per every wait milliseconds

Available since v1.9.0

import { throttle } from '@helpers4/function';
// or, from the all-in-one package (same code, one install):
import { throttle } from 'helpers4/function';
throttle<A extends unknown[], R>(func: function, wait: number): function
ParameterTypeDescription
funcfunctionThe function to throttle
waitnumberThe number of milliseconds to throttle invocations to

function — The throttled function

The throttled function is invoked at most once per wait period.

const fn = throttle(() => console.log('tick'), 100);
fn(); // executes immediately
fn(); // ignored (within wait period)

View source on GitHub