improve throttle function

This commit is contained in:
Ramón Souza 2023-11-01 11:12:15 -03:00
parent 0688cba0b4
commit 1b65c36743

View File

@ -22,7 +22,7 @@ export function throttle(func, delay, options = {}) {
if (leadingExec && leading) { if (leadingExec && leading) {
execute(); execute();
leadingExec = false; leadingExec = false;
const nextExecDelay = elapsed < delay ? delay - elapsed : 0; const nextExecDelay = elapsed < delay ? delay - elapsed : delay;
setTimeout(function () { setTimeout(function () {
leadingExec = true; leadingExec = true;
}, nextExecDelay); }, nextExecDelay);