@carbon/ibm-products
Version:
Carbon for IBM Products
22 lines (18 loc) • 479 B
JavaScript
/**
* Copyright IBM Corp. 2020, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
;
const throttle = function (fn) {
let delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100;
let time = Date.now();
return () => {
if (time + delay - Date.now() <= 0) {
fn();
time = Date.now();
}
};
};
exports.throttle = throttle;