Any news on
// EDIT: title of this post was 'Any news on "clearInterval()" bug' or something — <3 Q&A
I'm sorry that I don't even bother to reply to one of the few earlier posts regarding this subject, but the design of this "Q&A" section would effectively hide my response anyways. So I'll just open a new question.
Are there any news on the apparently broken "clearTimeout()" function yet? Or have I missed something?
// @ Titanium:
var foo = setTimeout(function(){Ti.API.info("foo");}, 5000);
var bar = setTimeout(function(){Ti.API.info("bar");}, 5000);
clearTimeout(bar);
// ... wait ...
// --> "foo"
// --> "bar"
// @ Safari JS console:
var foo = setTimeout(function(){Ti.API.info("foo");}, 5000);
var bar = setTimeout(function(){Ti.API.info("bar");}, 5000);
clearTimeout(bar);
// ... wait ...
// --> "foo"
Or has someone come-up with a work–around of some kind?
I'd be grateful for every hint! —Cheers.
1 Answer
-
I realize this is very late. This answer is for those who stumble upon this
question in a search. There are several questions surrounding this problem.
(Just to name a few):- clearTimeout() is broken » Community Questions & Answers
- Unable to stop timer (setTimeout) » Community Questions & Answers
- Please help on stopping the setTimeOut » Community Questions & Answers
The consensus seems to be that there is a fundamental flaw in Titanium's
implementation ofclearTimeout
. There for you need a work around. For example
avoiding the use ofclearTimeout
all together:var is_timer_still_active = true; function timerExecute() { if (!is_timer_still_active) { return; } is_timer_still_active = false; // Do my stuff here. } setTimeout(timerExecute, 2000); // To stop it: is_timer_still_active = false;
Hope you get the idea.