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.
1 Answer
-
Am also seeing the same issue in sdk 1.3.1. Is this being fixed?