Skip to content

Instantly share code, notes, and snippets.

@rogercampos
Created March 22, 2012 09:47
Show Gist options
  • Save rogercampos/2157400 to your computer and use it in GitHub Desktop.
Save rogercampos/2157400 to your computer and use it in GitHub Desktop.
Timed queue
// Use it like:
var myQueue = new TimedQueue(800);
// Call this 100 times in less than 500 ms:
myQueue.push(myCallback);
// myCallback function will be called only once, exactly 800 ms after the last call to 'push'
var TimedQueue = function(timeout) {
var identifier = null;
this.push = function(callback) {
window.clearTimeout(identifier);
identifier = setTimeout(callback, timeout);
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment