mrchimp / tock

Timer Object/Class. Kickass!
MIT License
237 stars 33 forks source link

Skip forward in time if diff becomes larger than interval #3

Closed scudco closed 11 years ago

scudco commented 11 years ago

I saw you mentioned it the updated README that this could be an issue, and indeed I already ran into it and fixed it with this code.

In a long running countdown timer that was doing some intensive work (redrawing a canvas element) in its callback it actually caused some confusing display problems. It eventually would run all the missing ticks, but the timer counted down very quickly rather than just rendering the latest real value.

This will just immediately run the tick function when this.interval - diff is less than or equal to zeor, and it will adjust this.time appropriately for the ticks it missed.

mrchimp commented 11 years ago

Nice one!