Titanium Community Questions & Answer Archive

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

Recurring Timer

Can I set a recurring timer so that I check certain conditions and do something periodically?

— asked March 27th 2010 by Peter Lum
  • recurring
  • timer
0 Comments

4 Answers

  • Accepted Answer

    setInterval ( "doSomething()", 5000 ); // runs every 5 seconds
    
    function doSomething ( )
    {
      // (do something here)
    }
    
    — answered March 27th 2010 by Mark Burggraf
    permalink
    0 Comments
  • Hey Peter,

    You can use Javascript's setInterval for that. An example would be:

    setInterval ( "doSomething()", 5000 );
    
    function doSomething ( )
    {
      // (do something here)
    }
    

    There's more info about setTimeout and setInterval here

    — answered March 27th 2010 by Dan Giulvezan
    permalink
    0 Comments
  • Hey Dan – we posted almost the exact same example at the exact same time. (But mine's better, because I added a comment :)

    Actually , setInterval is a little cleaner because you don't have to keep resetting it.

    — answered March 27th 2010 by Mark Burggraf
    permalink
    0 Comments
  • Oops, yeah, Mark's right. I pasted the wrong example. LOL

    setInterval is the way to go, I'll update my previous comment so the example matches what the comment says. :)

    — answered March 27th 2010 by Dan Giulvezan
    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.