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

Use the system clock to determine elapsed time #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

MicahChalmer
Copy link

Hi Rob,

I created a patch to make it use the system clock, rather than relying on receiving every interval, to determine the elapsed time. This allows it to show the true elapsed time even if it missed (or duplicated) some of its timer events, which should make it more accurate.

The main reason I did this was for use on Android and iOS. On iOS, if I go back to the home screen or switch to a different browser tab, the page stops receiving javascript timer events. On Android it manages to send events while in the background, but only until the screen goes to sleep. With the code as it stands, the stopwatch won't advance when it's not receiving events, so you can't trust the time it shows if the page isn't constantly visible. With my patch, it is able to catch up and display the true elapsed time, even if the device has gone to sleep in the middle.

I would also guess that this probably fixes the problem @Blacksus described in #6. I don't know if it actually does fix it, because I never ran into the #6 problem myself. But this patch would make it show an accurate elapsed time, even if the time between the interval events becomes weird.

This test makes a tick callback run for longer than the update interval
by busy-waiting.  The purpose of having it is that the stopwatch should
not rely on being able to get an interval event for each and every
interval.  Instead, it should use the amount of elapsed time as
measured by the system clock.
This test is to verify that the stopwatch's time does NOT increase
while the stopwatch is in a "stopped" state.  The codebase already
passes the test as of this commit, but when it is switched to actually
use the system clock to get the elapsed time, this becomes important
to verify.
@Yoda-BZH
Copy link

👍
Tested this weekend on ~24H, works as expected.
Fixes #6 for me.

Thanks !

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

Successfully merging this pull request may close these issues.

2 participants