avoid race condition in 06-advanced-functions/09-call-apply-decorators/04-throttle/solution.md
Well there is still a chance for a race condition but a smaller one. We would need an atomic "if or set" for isThrottled
This commit is contained in:
parent
d4b3c135cc
commit
c2cbc4cdaa
1 changed files with 1 additions and 2 deletions
|
@ -12,11 +12,10 @@ function throttle(func, ms) {
|
||||||
savedThis = this;
|
savedThis = this;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
isThrottled = true;
|
||||||
|
|
||||||
func.apply(this, arguments); // (1)
|
func.apply(this, arguments); // (1)
|
||||||
|
|
||||||
isThrottled = true;
|
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
isThrottled = false; // (3)
|
isThrottled = false; // (3)
|
||||||
if (savedArgs) {
|
if (savedArgs) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue