Created
January 19, 2010 16:51
-
-
Save Maciek416/281078 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var tick = function(){ | |
| /* ... compute stuff, do the work that needs to be done ... */ | |
| var data = ...; | |
| sendMessage(data); | |
| // schedule the next tick according to our course correction | |
| /* observe what time it is and how long it's been | |
| since a heartbeat and compute how much less than | |
| 500ms to delay for */ | |
| var currentTime = (new Date()).getTime(); | |
| var correctedDelay = ... /* compute scheduling correction */...; | |
| setTimeout(tick, correctedDelay); | |
| }; | |
| // initially delay by our "ideal time". Subsequent timings will be corrected and less-than-ideal | |
| setTimeout(tick, 500); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment