Skip to content

Instantly share code, notes, and snippets.

@wjramos
Last active June 8, 2017 03:15
Show Gist options
  • Save wjramos/a352aace2a56d2662004d9ae7f066d33 to your computer and use it in GitHub Desktop.
Save wjramos/a352aace2a56d2662004d9ae7f066d33 to your computer and use it in GitHub Desktop.
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