What I do is:
var timer = null;
if (timer != null) {
window.clearTimeout(timer);
timer = null;
}
else {
timer = window.setTimeout(yourFunction, 0);
}
More Related Contents:
- Why the timer setTimeout returns the first value “2”
- setTimeout in a for loop with array as an argument misbehaving
- Best way to iterate over an array without blocking the UI
- How to make a promise from setTimeout
- What is minimum millisecond value of setTimeout?
- Using setTimeout on promise chain
- Is there ever a good reason to pass a string to setTimeout?
- Why does setTimeout() “break” for large millisecond delay values?
- setTimeout ignores timeout? (Fires immediately) [duplicate]
- React hooks – right way to clear timeouts and intervals
- Why the function called by setTimeout has no callstack limit?
- What is setTimeout doing when set to 0 milliseconds?
- NodeJS Timeout a Promise if failed to complete in time
- How to make `setInterval` behave more in sync, or how to use `setTimeout` instead?
- setInterval in a React app
- Maximum call stack size exceeded on SetTimeout recursive function (Javascript) [duplicate]
- find the time left in a setTimeout()?
- using setTimeout synchronously in JavaScript
- How to test a function which has a setTimeout with jasmine?
- Get return value from setTimeout [duplicate]
- Is setTimeout with no delay the same as executing the function instantly?
- Why does the Promise object block rendering?
- Why is the function executed immediately when I use setTimeout?
- recursive function vs setInterval vs setTimeout javascript
- setTimeout not working inside forEach
- Why does everything display at once, using setTimeout in Javascript?
- Call setTimeout without delay
- how many javascript setTimeout/ setInterval call can be set simultaneously in one page?
- setTimeout(): If not defined in EcmaScript spec, where can I learn how it works?
- Is it bad practice to pass a string to settimeout? If yes, why? [duplicate]