Creates a rate-limited function that only invokes fn at most once per specified interval in milliseconds.
fn
interval
The function to rate-limit.
Minimum time in milliseconds between calls (default: 1000ms).
A rate-limited version of fn.
const log = (msg: string) => console.log(msg);const limitedLog = rateLimit(log, 2000);limitedLog("Hello"); // executes immediatelylimitedLog("World"); // ignored if called within 2 seconds Copy
const log = (msg: string) => console.log(msg);const limitedLog = rateLimit(log, 2000);limitedLog("Hello"); // executes immediatelylimitedLog("World"); // ignored if called within 2 seconds
1.1.0
Creates a rate-limited function that only invokes
fn
at most once per specifiedinterval
in milliseconds.