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:
Laurent Lyaudet 2021-03-24 17:27:49 +01:00 committed by GitHub
parent d4b3c135cc
commit c2cbc4cdaa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,11 +12,10 @@ function throttle(func, ms) {
savedThis = this;
return;
}
isThrottled = true;
func.apply(this, arguments); // (1)
isThrottled = true;
setTimeout(function() {
isThrottled = false; // (3)
if (savedArgs) {