Skip to content

Instantly share code, notes, and snippets.

@loktar00
Last active December 21, 2015 11:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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