Skip to content

Instantly share code, notes, and snippets.

@lukmdo
Created June 4, 2012 22:26
Show Gist options
  • Save lukmdo/2871182 to your computer and use it in GitHub Desktop.
Save lukmdo/2871182 to your computer and use it in GitHub Desktop.
self-delaying function
// quite same what _.debounce does http://underscorejs.org/#debounce
function self_delay(delay, just_run){
delay = delay || 3000;
clearTimeout(self_delay.sheduled);
if (!just_run){
self_delay.sheduled = setTimeout(self_delay, delay, 0, true);
return;
}
// logic/code comes here...
console.log('Hello - not more them once a %sms', delay);
};
// data fetching is only example could be any async code for ie touching the DOM
var urls = [];
$.each(urls, function(i, url){
$.get(url, function(data){
console.log('got data back from %s', url);
self_delay(2000);
});
});
// this could be turned into self delayed function generator ?!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment