Last active
June 8, 2017 03:15
-
-
Save wjramos/a352aace2a56d2662004d9ae7f066d33 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
export default class Timer { | |
constructor(callback, delay) { | |
this.callback = callback; | |
this.remaining = delay; | |
this.start(); | |
} | |
stop() { | |
this.timerId = clearTimeout(this.timerId); | |
this.remaining -= new Date() - this.startTime; | |
return this; | |
} | |
start() { | |
this.startTime = new Date(); | |
clearTimeout(this.timerId); | |
this.timerId = setTimeout(this.callback, this.remaining); | |
return this; | |
} | |
reset() { | |
} | |
clear() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment