Skip to content

throttle

Given an interval and a function returns a new function that will only call the source function if interval milliseconds have passed since the last invocation.

Usage

const sup = throttle({ interval: 1000 }, () => {
console.log("sup");
});
sup(); // => logs "sup"
sup(); // => no logs
setTimeout(() => sup(), 500); // => no logs
setTimeout(() => sup(), 1000); // => logs "sup"

Installation

Terminal window
npx atmx add helper throttle