Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Interval #6

Open
Blacksus opened this issue Aug 16, 2012 · 2 comments
Open

Update Interval #6

Blacksus opened this issue Aug 16, 2012 · 2 comments

Comments

@Blacksus
Copy link

Hello Rob,

I'm using your plugin for a long time, and it's so nice! But I found a problem that I couldn't understand well.
Sometimes, in some computers only, the timer goes crazy and start to count 2x faster, and sometimes jumping 1 second (counting 2 by 2).
I just don't know what to do, it's strange and I can't describe what happens... =/
There's nothing complicated in the code, just this:

$("#timer-atend").stopwatch({
startTime: parseInt(timeInitial, 10),
format: "{HH}:{MM}"
}).stopwatch('start');

Any idea what's going on?

Thank you so much Rob,
Have a nice day =]

@robcowie
Copy link
Owner

This is possibly due to the way setInterval() works. It will execute the callback every x seconds regardless of the successful completion of the previous invocation. It could therefore 'trip over' itself.

One possible fix is to replace setInterval() with recursive setTimeout() calls. This will stop the timer tripping-over itself and appearing to tick over faster than it should but it will potentially cause it to tick over more slowly than 'real time', i.e. 1 second may be displayed, but 1.5 seconds may have actually elapsed.

I'll have a think about it. For my info, what browser and OS was the machine using? Is the machine old? under heavy load?

@Blacksus
Copy link
Author

I'll try to change the function so, calling setTimeout()

I guess the browser isn't important, since the problem occurred in all browsers installed (Chrome, Firefox, Opera and IE), all with their lasted update. The machine isn't old (usually core i5 or i3, with 8GB RAM) and usually not under heavy load (some machines was under heavy load, but another machines no, with just IE opened)

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants