Skip to content

Instantly share code, notes, and snippets.

@Maciek416
Created January 19, 2010 16:51
Show Gist options
  • Select an option

  • Save Maciek416/281078 to your computer and use it in GitHub Desktop.

Select an option

Save Maciek416/281078 to your computer and use it in GitHub Desktop.
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