UNPKG

@carbon/ibm-products

Version:
26 lines (24 loc) 598 B
/** * Copyright IBM Corp. 2020, 2026 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ //#region src/global/js/utils/throttle.ts /** * Copyright IBM Corp. 2025, 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 = (fn, delay = 100) => { let time = Date.now(); return () => { if (time + delay - Date.now() <= 0) { fn(); time = Date.now(); } }; }; //#endregion exports.throttle = throttle;