latentflip / loupe

Visualizing the javascript runtime at runtime

Home Page:http://latentflip.com/loupe

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Clear Timeout is not Working as Expected Registered timeout executes even after

dubeyAditya opened this issue · comments

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]);
   } 
});

I think there are a few problems here:

  1. your timeouts might be too short given how slow the code runs
  2. the clearTimeout text is bound to text rather than button?
  3. 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.

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.