Skip to content

Instantly share code, notes, and snippets.

@steadicat
Created May 12, 2011 15:31
Show Gist options
  • Save steadicat/968753 to your computer and use it in GitHub Desktop.
Save steadicat/968753 to your computer and use it in GitHub Desktop.
function debounce(f, delay) {
var timeout;
return function() {
if (f.active) return WARNING('Refresh throttled: operation already started less than 5 seconds ago.');
f.active = true;
f.call(this, function() {
if (delay) {
if (timeout) clearTimeout(timeout);
timeout = setTimeout(function() { f.active = false }, delay);
} else {
f.active = false;
}
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment