README
@pacote/throttle
A tiny throttler.
Installation
yarn add @pacote/throttle
Usage
import { throttle } from '@pacote/throttle'
const throttledFn = throttle(fn, 100)
throttledFn() // fn() is called immediately
throttledFn() // fn() is scheduled for execution after 100ms
throttledFn() // fn() is scheduled for execution, cancelling the previous one
throttle<T>(fn: (...args: T[]) => any, delay = 0): (...args: T[]) => void
throttle()
creates a throttled version of the passed function.
By calling the throttled function repeatedly, the original function is called
once immediately and then at most once for every period of time determined by
the delay
argument.
The delay
argument is optional and defaults to 0
when not supplied.
The throttled function supplies a .cancel()
method that can be used to cancel
a pending invocation.
License
MIT © Luís Rodrigues.