@zendesk/retrace
Version:
define and capture Product Operation Traces along with computed metrics with an optional friendly React beacon API
22 lines • 728 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.throttle = void 0;
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable prefer-spread */
const throttle = (func, waitFor) => {
let previouslyRun;
let queuedToRun;
return function invokeFn(...args) {
const now = Date.now();
clearTimeout(queuedToRun);
if (!previouslyRun || now - previouslyRun >= waitFor) {
func.apply(null, args);
previouslyRun = now;
}
else {
queuedToRun = setTimeout(() => void invokeFn(...args), waitFor - (now - previouslyRun));
}
};
};
exports.throttle = throttle;
//# sourceMappingURL=throttle.js.map