Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Simple Repro Case for Broken setInterval/setTimeout behavior

It's been awhile since this was brought up on the Q&A and still no sign this is being looked at.

setTimeout and setInterval both exhibit behavior where the act of clearing them actually causes the interval/timeout to fire.

Very simple repro case:

var win1 = Titanium.UI.createWindow({  
    title:'Timeout/Interval Test',
    backgroundColor:'#fff'
});

var label1 = Titanium.UI.createLabel({
    text:'Interval Count: 0',
    font:{fontSize:20,fontFamily:'Helvetica Neue'},
    textAlign:'center',
    width:'auto'
});

win1.add(label1);
win1.open();
var i = 0;

var interval = setInterval(function() {
    Ti.API.info('Executing Interval');
    i++;
    label1.text = 'Interval Count: ' + i;
}, 100000);


setTimeout(function() {
    Ti.API.info('Clearing Interval');
    clearInterval(interval);
}, 1000);

You'll see that even though the interval should never fire, it fires (label1's text property is updated) when it is cleared after one second. Same thing happens with setTimeout. Lot of people have been hacking around this using state variables, but we have scenarios where using state variables doesn't work.

Surely this isn't expected behavior.

— asked May 25th 2010 by Alan McConnell
  • iphone
  • mobile
0 Comments

1 Answer

  • Am also seeing the same issue in sdk 1.3.1. Is this being fixed?

    — answered June 9th 2010 by Gaurav Srivastva
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.