-
Notifications
You must be signed in to change notification settings - Fork 33
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
Callback skipped #41
Comments
I am not quite sure yet why and how this worked (in https://github.com/mrchimp/tock/blob/master/tock.js#L50-L51) var diff = (Date.now() - this.start_time) - this.time,
next_interval_in = diff > 0 ? this.interval - diff : this.interval; but I changed it to this (in my local copy - currently) next_interval_in = this.start_time + this.time - Date.now() and I think it works better. |
I haven't got to the bottom of this yet but I've noticed a couple of things.
Hmmm. |
Did your observations happen with the current or still with my changed/suggested code? next_interval_in = this.start_time + this.time - Date.now() fixes the problem I'd create a PR. |
That actually made things worse for me. I will try to find some time to look into this but I'm super busy at the moment. I notice in the other thread that you're looking to use this for a drum machine. Tock's strength is that it doesn't drift over long periods of time, not that it is particularly accurate from tick to tick. It was originally made for a sports clock/scoreboard for example. it would be good for keeping a drum machine in time with another song, but not so great at making each individual beat be in time. This might be improved once I get around to implementing performance.now but - as much as I don't want to discourage you from using Tock - you might be better off using performance.now directly. |
Hm ok. It works pretty well for me with the above code. So I'll just keep using it for now. |
Hey,
I've got the problem that sometimes a callback is skipped.
I created a minimal example where I get the current tick with
Math.floor(tock.lap() / tock.interval)
*.I'd expect the list of ticks to be a list natural numbers.
But for some reason a tick is skipped at some point. Surprisingly, exactly until then the inaccuracy grows (see the console output).
Here's the example code:
Is my assumption simply wrong or do you agree that this should be an invariant?
Ok. I looked into it a bit more and the problem is the initial inaccuracy (until the 1st skipped tick).
Because of that the tick value without rounding (per callback) is growing from the correct value to
value + 1
. Here an example:An obvious workaround would be to have a closured tick variable that just gets incremented but the fact that all ticks before the 1st 'error' occurs are relatively inaccurate and all following ticks are good (as I would expect from the library) is weird...
The text was updated successfully, but these errors were encountered: