Skip to content

Commit

Permalink
fix(throttle): fixing throttle behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
danrevah committed May 31, 2019
1 parent cee74b4 commit 453dde5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/decorators/throttle/throttle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ function decorator(fn: (...args: any[]) => any, timeMs: number) {
return fn.apply(this, args);
} else {
const remaining = nextCall - now;

timeout && clearTimeout(timeout);
timeout = setTimeout(() => fn.apply(this, args), remaining);
timeout = setTimeout(() => {
nextCall = now + timeMs;
fn.apply(this, args);
}, remaining);
}
};
}

0 comments on commit 453dde5

Please sign in to comment.