Skip to content

Instantly share code, notes, and snippets.

@iamchristough
Created November 28, 2017 14:51
Show Gist options
  • Save iamchristough/528345fd5672539d8d1a2b383691310b to your computer and use it in GitHub Desktop.
Save iamchristough/528345fd5672539d8d1a2b383691310b to your computer and use it in GitHub Desktop.
function actThenThrottleEvents(listener, delay) {
var timeout;
return function(e) {
if (!timeout) { // no timer running
listener(e); // run the function
timeout = setTimeout( function() { timeout = null },
delay); // start a timer that turns itself off when it's done
}
//else, do nothing (we're in a throttling stage)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment