Skip to content

Instantly share code, notes, and snippets.

@thmain
Created December 25, 2022 05:30
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 thmain/fe149e3d695ce8eb35ab60cb0c880611 to your computer and use it in GitHub Desktop.
Save thmain/fe149e3d695ce8eb35ab60cb0c880611 to your computer and use it in GitHub Desktop.
function customSetInterval (cb, interval) {
return setTimeout( () => {
if (typeof cb == 'function') {
cb()
// Recurse
customSetInterval(cb, interval)
} else {
console.error(new Error('Expecting a function as a callback'))
}
}, interval)
}
function resetCustomSetInterval (id) {
clearTimeout(id)
}
function hello (){
console.log('hello')
}
let id = customSetInterval(hello, 1000)
let id2 = customSetInterval('hello', 1000) // [Error: Expecting a function as a callback]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment