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