Skip to content

Instantly share code, notes, and snippets.

@notshekhar
Created May 28, 2021 13:29
Show Gist options
  • Select an option

  • Save notshekhar/c4a40f693fed3fe4d9ce362544b84478 to your computer and use it in GitHub Desktop.

Select an option

Save notshekhar/c4a40f693fed3fe4d9ce362544b84478 to your computer and use it in GitHub Desktop.
//Ineterval control
class Interval{
constructor(fn, time){
this.fn = fn
this.time = time
this.timer = false;
}
start() {
if (!this.isRunning())
this.timer = setInterval(this.delayfn, this.delaytime);
};
stop() {
clearInterval(this.timer);
this.timer = false;
};
isRunning() {
return this.timer !== false;
};
static delay(milliseconds) {
let start = new Date().getTime();
for (let i = 0; i < i+2; i++) {
if ((new Date().getTime() - start) > milliseconds) {
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment