Skip to content

Instantly share code, notes, and snippets.

@okabe-yuya
Created January 1, 2021 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save okabe-yuya/983e4ef32c53eee33214c0895a844ec3 to your computer and use it in GitHub Desktop.
Save okabe-yuya/983e4ef32c53eee33214c0895a844ec3 to your computer and use it in GitHub Desktop.
slow down interval execution in javascript
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