Skip to content

Instantly share code, notes, and snippets.

@loktar00
Last active December 21, 2015 11:09
Show Gist options
  • Save loktar00/6296932 to your computer and use it in GitHub Desktop.
Save loktar00/6296932 to your computer and use it in GitHub Desktop.
Simple reoccurring timer
var timer = function (waitTime, callBack, forever, start) {
this.lastTime = Date.now();
this.waitTime = waitTime;
this.forever = forever;
this.running = start;
this.callBack = callBack;
this.tick = function () {
if (this.running) {
if (Date.now() > this.lastTime + this.waitTime) {
if(!this.forever){
this.running = false;
}
this.lastTime = Date.now();
this.callBack();
}
}
}
this.start = function () {
this.running = true;
}
this.stop = function(){
this.running = false;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment