Created
January 1, 2021 13:05
-
-
Save okabe-yuya/983e4ef32c53eee33214c0895a844ec3 to your computer and use it in GitHub Desktop.
slow down interval execution in javascript
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
const slowDownInterval = (ms, limit=10) => { | |
_slowDownInterval(ms, limit, 0); | |
} | |
const _slowDownInterval = (ms, limit, counter) => { | |
const sleepTimme = ms + (counter * 100); | |
if (limit > counter) { | |
setTimeout(() => { | |
console.log(`Interval: count => ${counter} ...`); | |
_slowDownInterval(ms, limit, counter + 1); | |
}, sleepTimme); | |
} | |
} | |
slowDownInterval(500, 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment