Last active
August 17, 2019 19:50
-
-
Save d0peCode/708016b96965cbf82cc81c96d0fed85c to your computer and use it in GitHub Desktop.
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 sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); | |
setTimeout(() => console.log('1200ms elapsed'), 1200); | |
const foo = () => { | |
let intervalId; | |
const intervalFunction = async() => { | |
clearInterval(intervalId); //clear so it will not execute again after 100ms | |
console.log('interval executed'); | |
await sleep(120); //some long action | |
return intervalId = setInterval(intervalFunction, 100); //reassign id and start after sleep() | |
}; | |
setInterval(intervalFunction, 100); | |
}; | |
foo(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment