Titanium JIRA Archive
Appcelerator Community (AC)

[AC-2729] iOS: setInterval loses 1 sec every 30 sec on certain devices

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionInvalid
Resolution Date2011-12-05T04:15:18.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsn/a
ReporterSumit Kataria
AssigneePaul Dowsett
Created2011-12-01T21:42:48.000+0000
Updated2016-03-08T07:47:37.000+0000

Description

setInterval function is not working correctly. It is losing time. In common language, if a watch counts 30 sec it is counting 29 sec. Attached project will demonstrate same. You can not replicate this in iOS simulator - this will happen only in devices. The timer function is extremely important for my project.

Attachments

FileDateSize
timer.zip2011-12-01T21:42:48.000+0000536702

Comments

  1. Paul Dowsett 2011-12-02

    Sumit Thank you for raising this issue. Your code contains a lot of unnecessary code that could be influencing the behavior. Would you please write a test case, as described in [Creating a Test Case](http://wiki.appcelerator.org/display/guides/How+to+Submit+a+Bug+Report#HowtoSubmitaBugReport-CreatingaTestCase)? Also, test cases should be added to the body of the ticket rather than as an attachment, to make it easy for the engineering team to assess. Once this is done, I will be able to move it across to the main project so that the engineering team can work on it. Thanks
  2. Paul Dowsett 2011-12-05

    As kindly, and correctly, explained by JongEun, Javascript timers are not guaranteed.
       > That's not a bug.
       > Javascript timer delay is not guranteed.
       > Becase Javascript excutes on a single thread.
       > Check this blog article
       > http://ejohn.org/blog/how-javascript-timers-work/
       >
       > You should not count in interval function :
       >
       > self.total_sec--;
       >
       >
       > how about this way?
       >
       > 1. when the timer start, save current Time
       >
       > 2.  just caculate time and update view on interval timer function
       >
       > var startTime = new Date();
       >
       > setInterval(function(){
       >
       >
       >   var timegap = new Date() - startTime;
       >
       >   // do somthing (such as update view ....)
       >
       >
       > },1000);
       >
       >
       > CodeStrong!
       >
       >
       > JongEun.
       
    This solution should resolve this for you. Hence, marking this ticket as invalid.
  3. Sumit Kataria 2011-12-05

    Thanks Paul for referring this. Yes above comment solved my blocker, but main issue is this is happening in a particular set of devices and others are behaving normally.
  4. Sumit Kataria 2011-12-05

    Closing ticket

JSON Source