Skip to content

Instantly share code, notes, and snippets.

@pietrom
Last active November 22, 2017 07:47
Show Gist options
  • Save pietrom/72ea08d9efc24534a98c605964e0ef22 to your computer and use it in GitHub Desktop.
Save pietrom/72ea08d9efc24534a98c605964e0ef22 to your computer and use it in GitHub Desktop.
Delayed function execution after the last invocation of an event handler
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