Skip to content

Instantly share code, notes, and snippets.

@bdelespierre
Created July 16, 2013 16:46
Show Gist options
  • Select an option

  • Save bdelespierre/6010416 to your computer and use it in GitHub Desktop.

Select an option

Save bdelespierre/6010416 to your computer and use it in GitHub Desktop.
(function () {
'use strict';
var get_synchronizer = function (delay, callback) {
var pretime = new Date().getTime();
return function () {
var curtime = new Date().getTime();
console.log(curtime - pretime);
if (curtime - pretime >= delay) {
callback();
pretime = curtime;
}
}
};
var sync = get_synchronizer(5000, function () {
console.log("il est " + new Date);
});
var runner = function () {
sync();
setTimeout(runner, 1000);
};
runner();
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment