⏱️ Creates a throttled function that only invokes func at most once per every interval milliseconds.
Syntax
TypeScript
import { paceRun } from '@opentf/std'; paceRun<T extends (...args: any[]) => any>( func: T, interval: number = 0, options?: { leading?: boolean; trailing?: boolean; } ): { (...args: Parameters<T>): void; cancel: () => void; flush: () => void; pending: () => boolean; };
Parameters
func: The function to throttle.interval: The number of milliseconds to throttle invocations to. Default:0.options:leading: Specify invoking on the leading edge of the timeout. Default:true.trailing: Specify invoking on the trailing edge of the timeout. Default:true.
interval must be a non-negative finite number.
Returns
The new throttled function.
Examples
TypeScript
const run = paceRun((val) => console.log(val), 500); run('a'); // Logs 'a' immediately (leading edge) run('b'); // Queued for trailing edge (default trailing: true)