Created
July 7, 2019 18:05
-
-
Save KamMif/cd6906bc3873f22b347060e824d443b9 to your computer and use it in GitHub Desktop.
add timeout
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
function timeout(ms, fn) { | |
let timer = setTimeout(() => { | |
if (timer) console.log('Function timedout'); | |
timer = null; | |
}, ms); | |
return (...args) => { | |
if (timer) { | |
timer = null; | |
fn(...args); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment