Class: KeyedThrottle<T>
Defined in: throttle.ts:269 Per-key throttle manager — wraps throttle with aMap keyed
by user-supplied identifiers so different keys throttle independently.
Use cases: per-endpoint throttles, per-user click handlers,
per-document save buffers. Memory grows with the number of distinct
keys; call cancel or cancelAll to free resources.
Example
Type Parameters
T
T extends AnyFunction
Function being throttled.
Constructors
Constructor
new KeyedThrottle<Defined in: throttle.ts:285T>(func,wait,options?):KeyedThrottle<T>
Parameters
func
T
Function to throttle. The same instance is used for
every key.
wait
number
Throttle window in milliseconds.
options?
Forwarded to throttle for each key’s internal throttled wrapper.leading?
boolean
trailing?
boolean
Returns
KeyedThrottle<T>
Methods
cancel()
cancel(Defined in: throttle.ts:314 Cancel any pending trailing-edge call forkey):void
key and drop the
bucket from the map. The next execute(key, …) will start fresh.
Parameters
key
string
Returns
void
cancelAll()
cancelAll(): void
Defined in: throttle.ts:323
Cancel and drop every bucket.
Returns
void
execute()
execute(Defined in: throttle.ts:299 Invokekey, …args):ReturnType<T> |undefined
func under the throttle bucket associated with key,
lazily creating that bucket on first call.
Parameters
key
string
args
…Parameters<T>
Returns
ReturnType<T> | undefined
Whatever the throttled call returns this tick — either
the freshly-computed result, the cached previous result, or
undefined if neither has fired yet.
getStats()
getStats(): object
Defined in: throttle.ts:336
Snapshot of currently-tracked keys.
Returns
object
{ activeKeys, keys }. The keys array is a one-shot
copy and not kept in sync with future mutations.
activeKeys
activeKeys: number
keys
keys: readonly string[]