Last active
November 22, 2017 07:47
-
-
Save pietrom/72ea08d9efc24534a98c605964e0ef22 to your computer and use it in GitHub Desktop.
Delayed function execution after the last invocation of an event handler
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
let timerId = null | |
const delay = 2000 | |
function delayedHandler() { | |
console.log('Hello, World!') | |
} | |
function onEvent() { | |
if(timerId) { | |
clearTimeout(timerId) | |
timerId = null | |
} | |
timerId = setTimeout(delayedHandler, delay) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment