@sapphire/utilities
Version:
Common JavaScript utilities for the Sapphire Community
30 lines (27 loc) • 634 B
JavaScript
;
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
// src/lib/throttle.ts
function throttle(func, wait) {
let prev = 0;
let prevValue;
return Object.assign(
(...args) => {
const now = Date.now();
if (now - prev > wait) {
prev = now;
return prevValue = func(...args);
}
return prevValue;
},
{
flush() {
prev = 0;
}
}
);
}
__name(throttle, "throttle");
exports.throttle = throttle;
//# sourceMappingURL=throttle.cjs.map
//# sourceMappingURL=throttle.cjs.map