Clear Timeout is not Working as Expected Registered timeout executes even after
dubeyAditya opened this issue · 2 comments
dubeyAditya commented
Following code Logs All the 5 logs on console even I click the Text in 4 seconds. But it works fine in my real code. I am not sure it is bug or I did something wrong. My main aim is to clear the timeout when some event happend. in between.
function timeout() {
console.log("Click the button!");
}
var arr = [];
$.on('button','click', function onClick() {
for(let i = 2000;i<12000;i+=2000)
{
arr.push(setTimeout(timeout, i,this));
}
});
$.on('text','click', function onClick() {
for(let i = 0;i<arr.length;i++)
{
clearTimeout(arr[i]);
}
});
latentflip commented
I think there are a few problems here:
- your timeouts might be too short given how slow the code runs
- the
clearTimeout
text is bound totext
rather thanbutton
? - I am not sure clearTimeout is actually implemented in loupe!
So yes, I'm afraid even if you fix your code here this probably will never work as you expect in loupe.
dubeyAditya commented
Even Timeouts are longer clearTimeout
is not workin. Any way you are the one who confirm it. Still it is more helpful for rest other cases.