Created
May 28, 2021 13:29
-
-
Save notshekhar/c4a40f693fed3fe4d9ce362544b84478 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
| //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