Titanium Community Questions & Answer Archive

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

clearTimeout does not work

I'm trying to set a timeout for a stream using the change event listner. The timeout does start, however, the clearTimeout doesn't work. It does not stop the timer. I can see from the log where the section of the clear timeout (else clause) is working, but the timer does not stop.

sound.addEventListener('change', function(e){
    Ti.API.info('state change ' + e.description);
    var errorTimer=0;
    if (e.description == "waiting_for_data") {
        Ti.API.info('starting timeout');
        errorTimer = setTimeout(function(){
            Ti.API.info("could not find file");
            dlStatus.text = 'Error!';
            playerNotes.text = 'File url cannot be accessed!';
        }, 5000);
    else {
        Ti.API.info('clearng timeout');

Any ideas?

— asked November 14th 2010 by Eli Mor
  • iphone
  • timeout

1 Answer

  • Accepted Answer

    You should define your timer outside your event. And not inside. When you define it inside your event it will be created every time.

    — answered November 15th 2010 by Jacob van Dam
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.