Last active
December 21, 2015 11:09
-
-
Save loktar00/6296932 to your computer and use it in GitHub Desktop.
Simple reoccurring timer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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